From 0dae2898e33bc8c5879ac10b69f7369b69b584e2 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Wed, 27 Jun 2012 14:49:36 +0200 Subject: [PATCH] fix vector resize to not always resize and actually use the reallocated place... --- exec.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/exec.c b/exec.c index dcc8718..bb4b59c 100644 --- a/exec.c +++ b/exec.c @@ -32,14 +32,23 @@ bool GMQCC_WARN Tself##_##mem##_append(Tself *s, Twhat *p, size_t c) \ bool GMQCC_WARN Tself##_##mem##_resize(Tself *s, size_t c) \ { \ Twhat *reall; \ - reall = (Twhat*)mem_a(sizeof(Twhat) * c); \ - if (c > s->mem##_count) { \ + if (c > s->mem##_alloc) { \ + reall = (Twhat*)mem_a(sizeof(Twhat) * c); \ + if (!reall) { return false; } \ memcpy(reall, s->mem, sizeof(Twhat) * s->mem##_count); \ - } else { \ - memcpy(reall, s->mem, sizeof(Twhat) * c); \ + s->mem##_alloc = c; \ + mem_d(s->mem); \ + s->mem = reall; \ + return true; \ } \ s->mem##_count = c; \ - s->mem##_alloc = c; \ + if (c < (s->mem##_alloc / 2)) { \ + reall = (Twhat*)mem_a(sizeof(Twhat) * c); \ + if (!reall) { return false; } \ + memcpy(reall, s->mem, sizeof(Twhat) * c); \ + mem_d(s->mem); \ + s->mem = reall; \ + } \ return true; \ } -- 2.39.2