changeset: 104742:deb3e5857d8c parent: 104740:849826a900d2 parent: 104741:8c2615decd2e user: INADA Naoki date: Thu Oct 27 19:30:10 2016 +0900 files: Misc/NEWS Objects/dictobject.c description: Issue #28509: dict.update() no longer allocate unnecessary large memory diff -r 849826a900d2 -r deb3e5857d8c Misc/NEWS --- a/Misc/NEWS Tue Oct 25 21:49:19 2016 -0500 +++ b/Misc/NEWS Thu Oct 27 19:30:10 2016 +0900 @@ -10,6 +10,8 @@ Core and Builtins ----------------- +- Issue #28509: dict.update() no longer allocate unnecessary large memory. + - Issue #28426: Fixed potential crash in PyUnicode_AsDecodedObject() in debug build. diff -r 849826a900d2 -r deb3e5857d8c Objects/dictobject.c --- a/Objects/dictobject.c Tue Oct 25 21:49:19 2016 -0500 +++ b/Objects/dictobject.c Thu Oct 27 19:30:10 2016 +0900 @@ -2407,9 +2407,11 @@ * incrementally resizing as we insert new items. Expect * that there will be no (or few) overlapping keys. */ - if (mp->ma_keys->dk_usable * 3 < other->ma_used * 2) - if (dictresize(mp, (mp->ma_used + other->ma_used)*2) != 0) + if (USABLE_FRACTION(mp->ma_keys->dk_size) < other->ma_used) { + if (dictresize(mp, ESTIMATE_SIZE(mp->ma_used + other->ma_used))) { return -1; + } + } ep0 = DK_ENTRIES(other->ma_keys); for (i = 0, n = other->ma_keys->dk_nentries; i < n; i++) { PyObject *key, *value;