summaryrefslogtreecommitdiffstats
path: root/Modules/_decimal
diff options
context:
space:
mode:
authorStefan Krah <skrah@bytereef.org>2012-04-09 18:47:57 (GMT)
committerStefan Krah <skrah@bytereef.org>2012-04-09 18:47:57 (GMT)
commitf69aef747a9a98eb130ed2e3b813ea4dfbfa1ae3 (patch)
treed2765aa5ed20a1fc21e042a21c32bf0d7f74a4c1 /Modules/_decimal
parent0c0914edb0fba3e31d6ad3aa70ef1822c21782f6 (diff)
downloadcpython-f69aef747a9a98eb130ed2e3b813ea4dfbfa1ae3.zip
cpython-f69aef747a9a98eb130ed2e3b813ea4dfbfa1ae3.tar.gz
cpython-f69aef747a9a98eb130ed2e3b813ea4dfbfa1ae3.tar.bz2
Resize the coefficient to MPD_MINALLOC also if the requested size is below
MPD_MINALLOC. Previously the resize was skipped as a micro optimization.
Diffstat (limited to 'Modules/_decimal')
-rw-r--r--Modules/_decimal/libmpdec/mpdecimal.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/Modules/_decimal/libmpdec/mpdecimal.c b/Modules/_decimal/libmpdec/mpdecimal.c
index 81a4108..fc2ac40 100644
--- a/Modules/_decimal/libmpdec/mpdecimal.c
+++ b/Modules/_decimal/libmpdec/mpdecimal.c
@@ -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_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 (nwords > result->alloc) {
return mpd_switch_to_dyn(result, nwords, status);
}
- }
- else if (nwords != result->alloc && nwords >= MPD_MINALLOC) {
- return mpd_realloc_dyn(result, nwords, status);
+ return 1;
}
- return 1;
+ return mpd_realloc_dyn(result, nwords, status);
}
/* 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_isshared_data(result)); /* illegal operation for a shared */
+ assert(MPD_MINALLOC <= result->alloc);
- if (mpd_isstatic_data(result)) {
- if (nwords > result->alloc) {
- return mpd_switch_to_dyn_zero(result, nwords, status);
+ nwords = (nwords <= MPD_MINALLOC) ? MPD_MINALLOC : nwords;
+ if (nwords != result->alloc) {
+ if (mpd_isstatic_data(result)) {
+ if (nwords > result->alloc) {
+ return mpd_switch_to_dyn_zero(result, nwords, status);
+ }
}
- }
- else if (nwords != result->alloc && nwords >= MPD_MINALLOC) {
- if (!mpd_realloc_dyn(result, nwords, status)) {
+ else if (!mpd_realloc_dyn(result, nwords, status)) {
return 0;
}
}
mpd_uint_zero(result->data, nwords);
-
return 1;
}