[Python-Dev] Rehashing in PyDict_Copy

Guido van Rossum guido@python.org
Thu, 29 Aug 2002 15:30:52 -0400

> Is there a reason that dict.copy() runs like an update()?
> It creates a new dict object, then re-hashes and inserts
> every element one-by-one, complete with collisions.
> I would have expected a single pass to update refcounts,
> an allocation for identical size, and a memcpy to polish
> it off.

After you've inserted and removed many elements into a dict, the
elements may not be in the best order, and there may be many "deleted"
markers.  The update() strategy avoids copying such cruft.

--Guido van Rossum (home page: http://www.python.org/~guido/)