summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2017-04-01 08:20:25 (GMT)
committerGitHub <noreply@github.com>2017-04-01 08:20:25 (GMT)
commite82cf8675bacd7a03de508ed11865fc2701dcef5 (patch)
tree757568ed2b04b890701340f29f40e7f0983f3c30 /Objects
parentcd815edf012dc6dd20dfeef91951270e96607616 (diff)
downloadcpython-e82cf8675bacd7a03de508ed11865fc2701dcef5.zip
cpython-e82cf8675bacd7a03de508ed11865fc2701dcef5.tar.gz
cpython-e82cf8675bacd7a03de508ed11865fc2701dcef5.tar.bz2
bpo-29949: Fix set memory usage regression (GH-943)
Revert "Minor factoring: move redundant resize scaling logic into the resize function." This reverts commit 4897300276d870f99459c82b937f0ac22450f0b6.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 2ccf183..23b32d0 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -236,7 +236,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
entry->hash = hash;
if ((size_t)so->fill*5 < mask*3)
return 0;
- return set_table_resize(so, so->used);
+ return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4);
found_active:
Py_DECREF(key);
@@ -302,7 +302,6 @@ set_table_resize(PySetObject *so, Py_ssize_t minused)
setentry small_copy[PySet_MINSIZE];
assert(minused >= 0);
- minused = (minused > 50000) ? minused * 2 : minused * 4;
/* Find the smallest table size > minused. */
/* XXX speed-up with intrinsics */
@@ -643,8 +642,8 @@ set_merge(PySetObject *so, PyObject *otherset)
* that there will be no (or few) overlapping keys.
*/
if ((so->fill + other->used)*5 >= so->mask*3) {
- if (set_table_resize(so, so->used + other->used) != 0)
- return -1;
+ if (set_table_resize(so, (so->used + other->used)*2) != 0)
+ return -1;
}
so_entry = so->table;
other_entry = other->table;
@@ -987,7 +986,7 @@ set_update_internal(PySetObject *so, PyObject *other)
if (dictsize < 0)
return -1;
if ((so->fill + dictsize)*5 >= so->mask*3) {
- if (set_table_resize(so, so->used + dictsize) != 0)
+ if (set_table_resize(so, (so->used + dictsize)*2) != 0)
return -1;
}
while (_PyDict_Next(other, &pos, &key, &value, &hash)) {
@@ -1507,7 +1506,7 @@ set_difference_update_internal(PySetObject *so, PyObject *other)
/* If more than 1/4th are dummies, then resize them away. */
if ((size_t)(so->fill - so->used) <= (size_t)so->mask / 4)
return 0;
- return set_table_resize(so, so->used);
+ return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4);
}
static PyObject *