Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16fa2a1

Browse files
committed
Forgot the "empty string -> hash == 0" special case for strings.
1 parent 802505d commit 16fa2a1

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Objects/unicodeobject.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11219,6 +11219,14 @@ unicode_hash(PyObject *self)
1121911219
if (PyUnicode_READY(self) == -1)
1122011220
return -1;
1122111221
len = PyUnicode_GET_LENGTH(self);
11222+
/*
11223+
We make the hash of the empty string be 0, rather than using
11224+
(prefix ^ suffix), since this slightly obfuscates the hash secret
11225+
*/
11226+
if (len == 0) {
11227+
_PyUnicode_HASH(self) = 0;
11228+
return 0;
11229+
}
1122211230

1122311231
/* The hash function as a macro, gets expanded three times below. */
1122411232
#define HASH(P) \

0 commit comments

Comments
 (0)