Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(16)

Side by Side Diff: Objects/unicodeobject.c

Issue 13704: Random number generator in Python core
Patch Set: Created 8 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 2
3 Unicode implementation based on original code by Fredrik Lundh, 3 Unicode implementation based on original code by Fredrik Lundh,
4 modified by Marc-Andre Lemburg <mal@lemburg.com>. 4 modified by Marc-Andre Lemburg <mal@lemburg.com>.
5 5
6 Major speed upgrades to the method implementations at the Reykjavik 6 Major speed upgrades to the method implementations at the Reykjavik
7 NeedForSpeed sprint, by Fredrik Lundh and Andrew Dalke. 7 NeedForSpeed sprint, by Fredrik Lundh and Andrew Dalke.
8 8
9 Copyright (c) Corporation for National Research Initiatives. 9 Copyright (c) Corporation for National Research Initiatives.
10 10
(...skipping 11089 matching lines...) Expand 10 before | Expand all | Expand 10 after
11100 Py_uhash_t x; 11100 Py_uhash_t x;
11101 11101
11102 if (_PyUnicode_HASH(self) != -1) 11102 if (_PyUnicode_HASH(self) != -1)
11103 return _PyUnicode_HASH(self); 11103 return _PyUnicode_HASH(self);
11104 if (PyUnicode_READY(self) == -1) 11104 if (PyUnicode_READY(self) == -1)
11105 return -1; 11105 return -1;
11106 len = PyUnicode_GET_LENGTH(self); 11106 len = PyUnicode_GET_LENGTH(self);
11107 11107
11108 /* The hash function as a macro, gets expanded three times below. */ 11108 /* The hash function as a macro, gets expanded three times below. */
11109 #define HASH(P) \ 11109 #define HASH(P) \
11110 x = (Py_uhash_t)*P << 7; \ 11110 x = Py_RndHashSeed + ((Py_uhash_t)*P << 7); \
gregory.p.smith 2012/01/15 02:18:38 Use ^ instead of +. Consistent with my suggestion
11111 while (--len >= 0) \ 11111 while (--len >= 0) \
11112 x = (1000003*x) ^ (Py_uhash_t)*P++; 11112 x = (1000003*x) ^ (Py_uhash_t)*P++;
11113 11113
11114 switch (PyUnicode_KIND(self)) { 11114 switch (PyUnicode_KIND(self)) {
11115 case PyUnicode_1BYTE_KIND: { 11115 case PyUnicode_1BYTE_KIND: {
11116 const unsigned char *c = PyUnicode_1BYTE_DATA(self); 11116 const unsigned char *c = PyUnicode_1BYTE_DATA(self);
11117 HASH(c); 11117 HASH(c);
11118 break; 11118 break;
11119 } 11119 }
11120 case PyUnicode_2BYTE_KIND: { 11120 case PyUnicode_2BYTE_KIND: {
(...skipping 3210 matching lines...) Expand 10 before | Expand all | Expand 10 after
14331 PyMODINIT_FUNC 14331 PyMODINIT_FUNC
14332 PyInit__string(void) 14332 PyInit__string(void)
14333 { 14333 {
14334 return PyModule_Create(&_string_module); 14334 return PyModule_Create(&_string_module);
14335 } 14335 }
14336 14336
14337 14337
14338 #ifdef __cplusplus 14338 #ifdef __cplusplus
14339 } 14339 }
14340 #endif 14340 #endif
OLDNEW

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+