Skip to content

Commit 008f036

Browse files
committed
add special case
1 parent 41c1cef commit 008f036

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Objects/stringlib/fastsearch.h

+9
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,15 @@ FASTSEARCH(const STRINGLIB_CHAR* s, Py_ssize_t n,
769769
return STRINGLIB(count_char)(s, n, p[0], maxcount);
770770
}
771771
}
772+
else if (n == m) {
773+
/* use special case when both strings are of equal length */
774+
int res = memcmp(s, p, m * sizeof(STRINGLIB_CHAR));
775+
if (mode == FAST_COUNT){
776+
return res == 0 ? 1 : 0;
777+
} else {
778+
return res == 0 ? 0 : -1;
779+
}
780+
}
772781

773782
if (mode != FAST_RSEARCH) {
774783
if (n < 2500 || (m < 100 && n < 30000) || m < 6) {

0 commit comments

Comments
 (0)