[Python-checkins] cpython: Add development comments to setobject.c

raymond.hettinger python-checkins at python.org
Sun May 18 22:40:29 CEST 2014


http://hg.python.org/cpython/rev/ec3ca1901776
changeset:   90757:ec3ca1901776
user:        Raymond Hettinger <python at rcn.com>
date:        Sun May 18 21:40:20 2014 +0100
summary:
  Add development comments to setobject.c

files:
  Objects/setobject.c |  23 +++++++++++++++--------
  1 files changed, 15 insertions(+), 8 deletions(-)


diff --git a/Objects/setobject.c b/Objects/setobject.c
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -4,7 +4,7 @@
    Written and maintained by Raymond D. Hettinger <python at rcn.com>
    Derived from Lib/sets.py and Objects/dictobject.c.
 
-   Copyright (c) 2003-2013 Python Software Foundation.
+   Copyright (c) 2003-2014 Python Software Foundation.
    All rights reserved.
 
    The basic lookup function used by all operations.
@@ -67,16 +67,16 @@
     while (1) {
         if (entry->key == key)
             return entry;
-        if (entry->hash == hash && entry->key != dummy) {
+        if (entry->hash == hash && entry->key != dummy) {         /* dummy match unlikely */
             PyObject *startkey = entry->key;
             Py_INCREF(startkey);
             cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
             Py_DECREF(startkey);
-            if (cmp < 0)
+            if (cmp < 0)                                          /* unlikely */
                 return NULL;
-            if (table != so->table || entry->key != startkey)
+            if (table != so->table || entry->key != startkey)     /* unlikely */
                 return set_lookkey(so, key, hash);
-            if (cmp > 0)
+            if (cmp > 0)                                          /* likely */
                 return entry;
         }
         if (entry->key == dummy && freeslot == NULL)
@@ -135,7 +135,7 @@
        including subclasses of str; e.g., one reason to subclass
        strings is to override __eq__, and for speed we don't cater to
        that here. */
-    if (!PyUnicode_CheckExact(key)) {
+    if (!PyUnicode_CheckExact(key)) {                             /* unlikely */
         so->lookup = set_lookkey;
         return set_lookkey(so, key, hash);
     }
@@ -147,8 +147,8 @@
     while (1) {
         if (entry->key == key
             || (entry->hash == hash
-                && entry->key != dummy
-                && unicode_eq(entry->key, key)))
+                && entry->key != dummy                            /* unlikely */
+                && unicode_eq(entry->key, key)))                  /* likely */
             return entry;
         if (entry->key == dummy && freeslot == NULL)
             freeslot = entry;
@@ -267,6 +267,7 @@
     assert(minused >= 0);
 
     /* Find the smallest table size > minused. */
+    /* XXX speed-up with intrinsics */
     for (newsize = PySet_MINSIZE;
          newsize <= minused && newsize > 0;
          newsize <<= 1)
@@ -1014,6 +1015,12 @@
 PyDoc_STRVAR(update_doc,
 "Update a set with the union of itself and others.");
 
+/* XXX Todo:
+   If aligned memory allocations become available, make the
+   set object 64 byte aligned so that most of the fields
+   can be retrieved or updated in a single cache line.
+*/
+
 static PyObject *
 make_new_set(PyTypeObject *type, PyObject *iterable)
 {

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list