Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String search is now up to to 20x faster when string and pattern are of the same size.
9 changes: 9 additions & 0 deletions Objects/stringlib/fastsearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,15 @@ FASTSEARCH(const STRINGLIB_CHAR* s, Py_ssize_t n,
return STRINGLIB(count_char)(s, n, p[0], maxcount);
}
}
else if (n == m) {
/* use special case when both strings are of equal length */
int res = memcmp(s, p, m * sizeof(STRINGLIB_CHAR));
if (mode == FAST_COUNT){
return res == 0 ? 1 : 0;
} else {
return res == 0 ? 0 : -1;
}
}

if (mode != FAST_RSEARCH) {
if (n < 2500 || (m < 100 && n < 30000) || m < 6) {
Expand Down
Loading