[pypy-svn] r28094 - in pypy/dist/pypy/objspace/std: . test

ale at codespeak.net ale at codespeak.net
Fri Jun 2 14:33:14 CEST 2006


Author: ale
Date: Fri Jun  2 14:33:13 2006
New Revision: 28094

Modified:
   pypy/dist/pypy/objspace/std/test/test_unicodeobject.py
   pypy/dist/pypy/objspace/std/unicodeobject.py
Log:
actually do hashes of empty unicode strings

Modified: pypy/dist/pypy/objspace/std/test/test_unicodeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_unicodeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_unicodeobject.py	Fri Jun  2 14:33:13 2006
@@ -20,6 +20,9 @@
         check(u'a' + 'b', u'ab')
         check('a' + u'b', u'ab')
 
+    def test_hash(self):
+        assert hash(u'') == 0
+        
     def test_join(self):
         def check(a, b):
             assert a == b

Modified: pypy/dist/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/unicodeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/unicodeobject.py	Fri Jun  2 14:33:13 2006
@@ -197,6 +197,8 @@
 def hash__Unicode(space, w_uni):
     if w_uni.w_hash is None:
         chars = w_uni._value
+        if len(chars) == 0:
+            return space.wrap(0)
         x = ord(chars[0]) << 7
         for c in chars:
             x = intmask((1000003 * x) ^ ord(c))



More information about the Pypy-commit mailing list