Raymond Hettinger added the comment:

Also, please take a look at resizing.  It looks like it is doing way too much 
work.  The original keys, values, and hashes shouldn't move at all, only the 
indices array needs to updated.

Here is the pure python version from the original proof-of-concept at 

    def _resize(self, n):
        '''Reindex the existing hash/key/value entries.
           Entries do not get moved, they only get new indices.
           No calls are made to hash() or __eq__().

        n = 2 ** n.bit_length()                     # round-up to power-of-two
        self.indices = self._make_index(n)
        for index, hashvalue in enumerate(self.hashlist):
            for i in Dict._gen_probes(hashvalue, n-1):
                if self.indices[i] == FREE:
            self.indices[i] = index
        self.filled = self.used

Likewise, it looks like there is room for improvement in dict_copy().  It can 
memcpy() all four arrays and then incref all the keys.  That should be 
considerably faster than zeroing new arrays and applying re-insertion logic.


Python tracker <rep...@bugs.python.org>
Python-bugs-list mailing list

Reply via email to