[Python-checkins] cpython: Remove an unnecessary extra copy of the bytes hash function.

gregory.p.smith python-checkins at python.org
Sun Jan 15 00:09:39 CET 2012


http://hg.python.org/cpython/rev/4ac9ff649f5b
changeset:   74413:4ac9ff649f5b
parent:      74409:06d96a5bb41e
user:        Gregory P. Smith <greg at krypto.org>
date:        Sat Jan 14 14:31:13 2012 -0800
summary:
  Remove an unnecessary extra copy of the bytes hash function.

This copy also had a bug in it, it fails to incorporate the length
into the hash by using it as the loop variable so it'll always be -1
by the time it is XORed in.

As such: I'm doing this only in Python 3.3 and not backporting as it
would change the existing hash behavior of datetime objects.

files:
  Modules/_datetimemodule.c |  16 +---------------
  1 files changed, 1 insertions(+), 15 deletions(-)


diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -2755,24 +2755,10 @@
     return clone;
 }
 
-/*
-    Borrowed from stringobject.c, originally it was string_hash()
-*/
 static Py_hash_t
 generic_hash(unsigned char *data, int len)
 {
-    register unsigned char *p;
-    register Py_uhash_t x;
-
-    p = (unsigned char *) data;
-    x = (Py_uhash_t)*p << 7;
-    while (--len >= 0)
-        x = (1000003U*x) ^ (Py_uhash_t)*p++;
-    x ^= (Py_uhash_t)len;
-    if (x == -1)
-        x = -2;
-
-    return x;
+    return _Py_HashBytes(data, len);
 }
 
 

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


More information about the Python-checkins mailing list