summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-05-17 22:25:34 +0000
committerTim Peters <tim.peters@gmail.com>2001-05-17 22:25:34 +0000
commit1928314ef470e038b104162735eb3fa752ea9ba0 (patch)
treeb5a301b1fc8c80dff4ed20a0209161d320e1896d
parentb686791b77dbd3394186b2c36e8f5aa6e1c7e734 (diff)
downloadcpython-git-1928314ef470e038b104162735eb3fa752ea9ba0.tar.gz
Speed dictresize by collapsing its two passes into one; the reason given
in the comments for using two passes was bogus, as the only object that can get decref'ed due to the copy is the dummy key, and decref'ing dummy can't have side effects (for one thing, dummy is immortal! for another, it's a string object, not a potentially dangerous user-defined object).
-rw-r--r--Objects/dictobject.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index b0121ed650..b465a219ef 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -396,16 +396,17 @@ dictresize(dictobject *mp, int minused)
mp->ma_fill = 0;
mp->ma_used = 0;
- /* Make two passes, so we can avoid decrefs
- (and possible side effects) till the table is copied */
+ /* Copy the data over; this is refcount-neutral for active entries;
+ dummy entries aren't copied over, of course */
for (i = 0, ep = oldtable; i < oldsize; i++, ep++) {
- if (ep->me_value != NULL)
- insertdict(mp,ep->me_key,ep->me_hash,ep->me_value);
- }
- for (i = 0, ep = oldtable; i < oldsize; i++, ep++) {
- if (ep->me_value == NULL) {
- Py_XDECREF(ep->me_key);
+ if (ep->me_value != NULL) /* active entry */
+ insertdict(mp, ep->me_key, ep->me_hash, ep->me_value);
+
+ else if (ep->me_key != NULL) { /* dummy entry */
+ assert(ep->me_key == dummy);
+ Py_DECREF(ep->me_key);
}
+ /* else key == value == NULL: nothing to do */
}
if (oldtable != NULL)