Author: guido.van.rossum
Date: Tue Sep 18 06:30:42 2007
New Revision: 58187

Modified:
   python/branches/py3k/Objects/dictobject.c
   python/branches/py3k/Objects/unicodeobject.c
Log:
Micro optimizations after staring at gprof output for a while.


Modified: python/branches/py3k/Objects/dictobject.c
==============================================================================
--- python/branches/py3k/Objects/dictobject.c   (original)
+++ python/branches/py3k/Objects/dictobject.c   Tue Sep 18 06:30:42 2007
@@ -566,8 +566,8 @@
        PyThreadState *tstate;
        if (!PyDict_Check(op))
                return NULL;
-       if (!PyString_CheckExact(key) ||
-           (hash = ((PyStringObject *) key)->ob_shash) == -1)
+       if (!PyUnicode_CheckExact(key) ||
+           (hash = ((PyUnicodeObject *) key)->hash) == -1)
        {
                hash = PyObject_Hash(key);
                if (hash == -1) {
@@ -650,12 +650,9 @@
        assert(key);
        assert(value);
        mp = (dictobject *)op;
-       if (PyString_CheckExact(key)) {
-               hash = ((PyStringObject *)key)->ob_shash;
-               if (hash == -1)
-                       hash = PyObject_Hash(key);
-       }
-       else {
+       if (!PyUnicode_CheckExact(key) ||
+           (hash = ((PyUnicodeObject *) key)->hash) == -1)
+       {
                hash = PyObject_Hash(key);
                if (hash == -1)
                        return -1;

Modified: python/branches/py3k/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k/Objects/unicodeobject.c        (original)
+++ python/branches/py3k/Objects/unicodeobject.c        Tue Sep 18 06:30:42 2007
@@ -6597,9 +6597,10 @@
         /* Since Unicode objects compare equal to their UTF-8 string
            counterparts, we hash the UTF-8 string. */
         PyObject *v = _PyUnicode_AsDefaultEncodedString((PyObject*)self, NULL);
-        long x = PyObject_Hash(v);
-        self->hash = x;
-        return x;
+        if (v == NULL)
+            return -1;
+        assert(PyString_CheckExact(v));
+        return self->hash = v->ob_type->tp_hash(v);
     }
 }
 
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to