summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2012-02-20 23:50:13 (GMT)
committerGeorg Brandl <georg@python.org>2012-02-20 23:50:13 (GMT)
commit16fa2a10970a92cba1ee1249ed7bcf7d2c131051 (patch)
treec0d1d0ae9fe7c301883f69b22a889935021b5070 /Objects
parent802505d05e7346df9d0a8feea61f22deaf48d268 (diff)
downloadcpython-16fa2a10970a92cba1ee1249ed7bcf7d2c131051.zip
cpython-16fa2a10970a92cba1ee1249ed7bcf7d2c131051.tar.gz
cpython-16fa2a10970a92cba1ee1249ed7bcf7d2c131051.tar.bz2
Forgot the "empty string -> hash == 0" special case for strings.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 716ca3f..75e9923 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -11219,6 +11219,14 @@ unicode_hash(PyObject *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
+ */
+ if (len == 0) {
+ _PyUnicode_HASH(self) = 0;
+ return 0;
+ }
/* The hash function as a macro, gets expanded three times below. */
#define HASH(P) \