Resize the coefficient to MPD_MINALLOC also if the requested size is below

MPD_MINALLOC. Previously the resize was skipped as a micro optimization.
This commit is contained in:
Stefan Krah 2012-04-09 20:47:57 +02:00
parent 0c0914edb0
commit f69aef747a
1 changed files with 15 additions and 11 deletions

View File

@ -480,17 +480,20 @@ mpd_qresize(mpd_t *result, mpd_ssize_t nwords, uint32_t *status)
{ {
assert(!mpd_isconst_data(result)); /* illegal operation for a const */ assert(!mpd_isconst_data(result)); /* illegal operation for a const */
assert(!mpd_isshared_data(result)); /* illegal operation for a shared */ assert(!mpd_isshared_data(result)); /* illegal operation for a shared */
assert(MPD_MINALLOC <= result->alloc);
nwords = (nwords <= MPD_MINALLOC) ? MPD_MINALLOC : nwords;
if (nwords == result->alloc) {
return 1;
}
if (mpd_isstatic_data(result)) { if (mpd_isstatic_data(result)) {
if (nwords > result->alloc) { if (nwords > result->alloc) {
return mpd_switch_to_dyn(result, nwords, status); return mpd_switch_to_dyn(result, nwords, status);
} }
} return 1;
else if (nwords != result->alloc && nwords >= MPD_MINALLOC) {
return mpd_realloc_dyn(result, nwords, status);
} }
return 1; return mpd_realloc_dyn(result, nwords, status);
} }
/* Same as mpd_qresize, but the complete coefficient (including the old /* Same as mpd_qresize, but the complete coefficient (including the old
@ -500,20 +503,21 @@ mpd_qresize_zero(mpd_t *result, mpd_ssize_t nwords, uint32_t *status)
{ {
assert(!mpd_isconst_data(result)); /* illegal operation for a const */ assert(!mpd_isconst_data(result)); /* illegal operation for a const */
assert(!mpd_isshared_data(result)); /* illegal operation for a shared */ assert(!mpd_isshared_data(result)); /* illegal operation for a shared */
assert(MPD_MINALLOC <= result->alloc);
nwords = (nwords <= MPD_MINALLOC) ? MPD_MINALLOC : nwords;
if (nwords != result->alloc) {
if (mpd_isstatic_data(result)) { if (mpd_isstatic_data(result)) {
if (nwords > result->alloc) { if (nwords > result->alloc) {
return mpd_switch_to_dyn_zero(result, nwords, status); return mpd_switch_to_dyn_zero(result, nwords, status);
} }
} }
else if (nwords != result->alloc && nwords >= MPD_MINALLOC) { else if (!mpd_realloc_dyn(result, nwords, status)) {
if (!mpd_realloc_dyn(result, nwords, status)) {
return 0; return 0;
} }
} }
mpd_uint_zero(result->data, nwords); mpd_uint_zero(result->data, nwords);
return 1; return 1;
} }