Commits

Armin Rigo committed aab5186

Remove a '/ 3' in ll_dict_setitem(). Probably not measurable, but I suppose
it's part of the general "this looks better" theory.

  • Participants
  • Parent commits 7b8611a

Comments (0)

Files changed (4)

File pypy/rlib/_rweakkeydict.py

     d = lltype.malloc(WEAKDICT)
     d.entries = WEAKDICT.entries.TO.allocate(rdict.DICT_INITSIZE)
     d.num_items = 0
-    d.num_pristine_entries = rdict.DICT_INITSIZE
+    d.resize_counter = rdict.DICT_INITSIZE * 2
     return d
 
 @jit.dont_look_inside
     #                 ll_debugrepr(llkey),
     #                 ll_debugrepr(llvalue))
     if not everused:
-        d.num_pristine_entries -= 1
-        if d.num_pristine_entries * 3 <= len(d.entries):
+        d.resize_counter -= 3
+        if d.resize_counter <= 0:
             #llop.debug_print(lltype.Void, 'RESIZE')
             ll_weakdict_resize(d)
 
 
 WEAKDICT = lltype.GcStruct("weakkeydict",
                            ("num_items", lltype.Signed),
-                           ("num_pristine_entries", lltype.Signed),
+                           ("resize_counter", lltype.Signed),
                            ("entries", lltype.Ptr(WEAKDICTENTRYARRAY)),
                            adtmeths=dictmeths)

File pypy/rlib/_rweakvaldict.py

         self.WEAKDICT = lltype.GcStruct(
             "weakvaldict",
             ("num_items", lltype.Signed),
-            ("num_pristine_entries", lltype.Signed),
+            ("resize_counter", lltype.Signed),
             ("entries", lltype.Ptr(WEAKDICTENTRYARRAY)),
             adtmeths=dictmeths)
 
         d = lltype.malloc(self.WEAKDICT)
         d.entries = self.WEAKDICT.entries.TO.allocate(rdict.DICT_INITSIZE)
         d.num_items = 0
-        d.num_pristine_entries = rdict.DICT_INITSIZE
+        d.resize_counter = rdict.DICT_INITSIZE * 2
         return d
 
     @jit.dont_look_inside
         d.entries[i].value = valueref
         #llop.debug_print(lltype.Void, i, 'stored')
         if not everused:
-            d.num_pristine_entries -= 1
-            if d.num_pristine_entries * 3 <= len(d.entries):
+            d.resize_counter -= 3
+            if d.resize_counter <= 0:
                 #llop.debug_print(lltype.Void, 'RESIZE')
                 self.ll_weakdict_resize(d)
 

File pypy/rpython/lltypesystem/rdict.py

 #  DICTVALUE types.
 #
 #  XXX for immutable dicts, the array should be inlined and
-#      num_pristine_entries and everused are not needed.
+#      resize_counter and everused are not needed.
 #
 #    struct dictentry {
 #        DICTKEY key;
 #
 #    struct dicttable {
 #        int num_items;
-#        int num_pristine_entries;  # never used entries
+#        int resize_counter;
 #        Array *entries;
 #        (Function DICTKEY, DICTKEY -> bool) *fnkeyeq;
 #        (Function DICTKEY -> int) *fnkeyhash;
             self.DICTENTRYARRAY = lltype.GcArray(self.DICTENTRY,
                                                  adtmeths=entrymeths)
             fields =          [ ("num_items", lltype.Signed),
-                                ("num_pristine_entries", lltype.Signed),
+                                ("resize_counter", lltype.Signed),
                                 ("entries", lltype.Ptr(self.DICTENTRYARRAY)) ]
             if self.custom_eq_hash:
                 self.r_rdict_eqfn, self.r_rdict_hashfn = self._custom_eq_hash_repr()
     d.num_items += 1
     if not everused:
         if hasattr(ENTRY, 'f_everused'): entry.f_everused = True
-        d.num_pristine_entries -= 1
-        if d.num_pristine_entries <= len(d.entries) / 3:
+        d.resize_counter -= 3
+        if d.resize_counter <= 0:
             ll_dict_resize(d)
 
 def ll_dict_insertclean(d, key, value, hash):
     if hasattr(ENTRY, 'f_valid'):    entry.f_valid = True
     if hasattr(ENTRY, 'f_everused'): entry.f_everused = True
     d.num_items += 1
-    d.num_pristine_entries -= 1
+    d.resize_counter -= 3
 
 def ll_dict_delitem(d, key):
     i = ll_dict_lookup(d, key, d.keyhash(key))
         new_size /= 2
     d.entries = lltype.typeOf(old_entries).TO.allocate(new_size)
     d.num_items = 0
-    d.num_pristine_entries = new_size
+    d.resize_counter = new_size * 2
     i = 0
     while i < old_size:
         if old_entries.valid(i):
     d = DICT.allocate()
     d.entries = DICT.entries.TO.allocate(DICT_INITSIZE)
     d.num_items = 0
-    d.num_pristine_entries = DICT_INITSIZE
+    d.resize_counter = DICT_INITSIZE * 2
     return d
 ll_newdict.oopspec = 'newdict()'
 
     d = DICT.allocate()
     d.entries = DICT.entries.TO.allocate(n)
     d.num_items = 0
-    d.num_pristine_entries = n
+    d.resize_counter = n * 2
     return d
 ll_newdict_size.oopspec = 'newdict()'
 
     d = DICT.allocate()
     d.entries = DICT.entries.TO.allocate(dictsize)
     d.num_items = dict.num_items
-    d.num_pristine_entries = dict.num_pristine_entries
+    d.resize_counter = dict.resize_counter
     if hasattr(DICT, 'fnkeyeq'):   d.fnkeyeq   = dict.fnkeyeq
     if hasattr(DICT, 'fnkeyhash'): d.fnkeyhash = dict.fnkeyhash
     i = 0
 ll_copy.oopspec = 'dict.copy(dict)'
 
 def ll_clear(d):
-    if len(d.entries) == d.num_pristine_entries == DICT_INITSIZE:
+    if (len(d.entries) == DICT_INITSIZE and
+        d.resize_counter == DICT_INITSIZE * 2):
         return
     old_entries = d.entries
     d.entries = lltype.typeOf(old_entries).TO.allocate(DICT_INITSIZE)
     d.num_items = 0
-    d.num_pristine_entries = DICT_INITSIZE
+    d.resize_counter = DICT_INITSIZE * 2
     old_entries.delete()
 ll_clear.oopspec = 'dict.clear(d)'
 

File pypy/rpython/memory/lldict.py

                        })
 DICT = lltype.Struct('DICT', ('entries', lltype.Ptr(ENTRIES)),
                              ('num_items', lltype.Signed),
-                             ('num_pristine_entries', lltype.Signed),
+                             ('resize_counter', lltype.Signed),
                      adtmeths = {
                          'allocate': dict_allocate,
                          'delete': dict_delete,