Skip to content

Commit b1b915c

Browse files
committed
Issue 18719: Remove a false optimization
Remove an unused early-out test from the critical path for dict and set lookups. When the strings already have matching lengths, kinds, and hashes, there is no additional information gained by checking the first characters (the probability of a mismatch is already known to be less than 1 in 2**64).
1 parent 0a01ac4 commit b1b915c

File tree

1 file changed

+0
-9
lines changed
  • Objects/stringlib

1 file changed

+0
-9
lines changed

Objects/stringlib/eq.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ unicode_eq(PyObject *aa, PyObject *bb)
2020
return 1;
2121
if (PyUnicode_KIND(a) != PyUnicode_KIND(b))
2222
return 0;
23-
/* Just comparing the first byte is enough to see if a and b differ.
24-
* If they are 2 byte or 4 byte character most differences will happen in
25-
* the lower bytes anyways.
26-
*/
27-
if (PyUnicode_1BYTE_DATA(a)[0] != PyUnicode_1BYTE_DATA(b)[0])
28-
return 0;
29-
if (PyUnicode_KIND(a) == PyUnicode_1BYTE_KIND &&
30-
PyUnicode_GET_LENGTH(a) == 1)
31-
return 1;
3223
return memcmp(PyUnicode_1BYTE_DATA(a), PyUnicode_1BYTE_DATA(b),
3324
PyUnicode_GET_LENGTH(a) * PyUnicode_KIND(a)) == 0;
3425
}

0 commit comments

Comments
 (0)