| OLD | NEW |
| 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> according to the | 4 modified by Marc-Andre Lemburg <mal@lemburg.com> according to the |
| 5 Unicode Integration Proposal (see file Misc/unicode.txt). | 5 Unicode Integration Proposal (see file Misc/unicode.txt). |
| 6 | 6 |
| 7 Major speed upgrades to the method implementations at the Reykjavik | 7 Major speed upgrades to the method implementations at the Reykjavik |
| 8 NeedForSpeed sprint, by Fredrik Lundh and Andrew Dalke. | 8 NeedForSpeed sprint, by Fredrik Lundh and Andrew Dalke. |
| 9 | 9 |
| 10 Copyright (c) Corporation for National Research Initiatives. | 10 Copyright (c) Corporation for National Research Initiatives. |
| (...skipping 7326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7337 static long | 7337 static long |
| 7338 unicode_hash(PyUnicodeObject *self) | 7338 unicode_hash(PyUnicodeObject *self) |
| 7339 { | 7339 { |
| 7340 Py_ssize_t len; | 7340 Py_ssize_t len; |
| 7341 Py_UNICODE *p; | 7341 Py_UNICODE *p; |
| 7342 long x; | 7342 long x; |
| 7343 | 7343 |
| 7344 if (self->hash != -1) | 7344 if (self->hash != -1) |
| 7345 return self->hash; | 7345 return self->hash; |
| 7346 len = Py_SIZE(self); | 7346 len = Py_SIZE(self); |
| 7347 /* |
| 7348 We make the hash of the empty string be 0, rather than using |
| 7349 (prefix ^ suffix), since this slightly obfuscates the hash secret |
| 7350 */ |
| 7351 if (len == 0) { |
| 7352 self->hash = 0; |
| 7353 return 0; |
| 7354 } |
| 7347 p = self->str; | 7355 p = self->str; |
| 7348 x = *p << 7; | 7356 x = _Py_HashSecret.prefix; |
| 7357 x ^= *p << 7; |
| 7349 while (--len >= 0) | 7358 while (--len >= 0) |
| 7350 x = (1000003*x) ^ *p++; | 7359 x = (1000003*x) ^ *p++; |
| 7351 x ^= Py_SIZE(self); | 7360 x ^= Py_SIZE(self); |
| 7361 x ^= _Py_HashSecret.suffix; |
| 7352 if (x == -1) | 7362 if (x == -1) |
| 7353 x = -2; | 7363 x = -2; |
| 7354 self->hash = x; | 7364 self->hash = x; |
| 7355 return x; | 7365 return x; |
| 7356 } | 7366 } |
| 7357 | 7367 |
| 7358 PyDoc_STRVAR(index__doc__, | 7368 PyDoc_STRVAR(index__doc__, |
| 7359 "S.index(sub[, start[, end]]) -> int\n\ | 7369 "S.index(sub[, start[, end]]) -> int\n\ |
| 7360 \n\ | 7370 \n\ |
| 7361 Like S.find() but raise ValueError when the substring is not found."); | 7371 Like S.find() but raise ValueError when the substring is not found."); |
| (...skipping 2675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10037 } | 10047 } |
| 10038 #endif | 10048 #endif |
| 10039 | 10049 |
| 10040 | 10050 |
| 10041 /* | 10051 /* |
| 10042 Local variables: | 10052 Local variables: |
| 10043 c-basic-offset: 4 | 10053 c-basic-offset: 4 |
| 10044 indent-tabs-mode: nil | 10054 indent-tabs-mode: nil |
| 10045 End: | 10055 End: |
| 10046 */ | 10056 */ |
| OLD | NEW |