mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-20 18:32:01 +00:00
fix vector resize to not always resize and actually use the reallocated place...
This commit is contained in:
parent
a6e7baf127
commit
0dae2898e3
1 changed files with 14 additions and 5 deletions
19
exec.c
19
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; \
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue