]> granicus.if.org Git - python/commitdiff
merge 3.2 (#14509)
authorBenjamin Peterson <benjamin@python.org>
Mon, 9 Apr 2012 19:04:39 +0000 (15:04 -0400)
committerBenjamin Peterson <benjamin@python.org>
Mon, 9 Apr 2012 19:04:39 +0000 (15:04 -0400)
1  2 
Objects/object.c
Objects/unicodeobject.c

index 5bafbc00e0b9bf488665f199b8b873f1ea8a5b21,84ec2f34f582ea623dbb4759ec9440844aefd08c..c8c1861a4dfd2366a6e31e24203de07686509420
@@@ -753,31 -746,6 +753,33 @@@ _Py_HashPointer(void *p
      return x;
  }
  
 +Py_hash_t
 +_Py_HashBytes(unsigned char *p, Py_ssize_t len)
 +{
 +    Py_uhash_t x;
 +    Py_ssize_t i;
 +
 +    /*
 +      We make the hash of the empty string be 0, rather than using
 +      (prefix ^ suffix), since this slightly obfuscates the hash secret
 +    */
++#ifdef Py_DEBUG
 +    assert(_Py_HashSecret_Initialized);
++#endif
 +    if (len == 0) {
 +        return 0;
 +    }
 +    x = (Py_uhash_t) _Py_HashSecret.prefix;
 +    x ^= (Py_uhash_t) *p << 7;
 +    for (i = 0; i < len; i++)
 +        x = (_PyHASH_MULTIPLIER * x) ^ (Py_uhash_t) *p++;
 +    x ^= (Py_uhash_t) len;
 +    x ^= (Py_uhash_t) _Py_HashSecret.suffix;
 +    if (x == -1)
 +        x = -2;
 +    return x;
 +}
 +
  Py_hash_t
  PyObject_HashNotImplemented(PyObject *v)
  {
index bff33d9ad046a55cc96f69e00a997f67b86bdda0,cd17789f53bb87929f3f373b19688d421e47d137..7e73bc226c16862d46164bafe93b53ab857d80ec
@@@ -11328,19 -7665,20 +11328,21 @@@ unicode_getitem(PyObject *self, Py_ssiz
  }
  
  /* Believe it or not, this produces the same value for ASCII strings
 -   as string_hash(). */
 +   as bytes_hash(). */
  static Py_hash_t
 -unicode_hash(PyUnicodeObject *self)
 +unicode_hash(PyObject *self)
  {
      Py_ssize_t len;
 -    Py_UNICODE *p;
 -    Py_hash_t x;
 +    Py_uhash_t x;
  
+ #ifdef Py_DEBUG
      assert(_Py_HashSecret_Initialized);
 -    if (self->hash != -1)
 -        return self->hash;
 -    len = Py_SIZE(self);
+ #endif
 +    if (_PyUnicode_HASH(self) != -1)
 +        return _PyUnicode_HASH(self);
 +    if (PyUnicode_READY(self) == -1)
 +        return -1;
 +    len = PyUnicode_GET_LENGTH(self);
      /*
        We make the hash of the empty string be 0, rather than using
        (prefix ^ suffix), since this slightly obfuscates the hash secret