diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-04-07 22:26:43 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-04-07 22:26:43 (GMT) |
commit | 7efa3b8242771f5e63ffaab7bd184e1a5c12c429 (patch) | |
tree | 2d0722f33950bdd49a67066509d0aeab52fc45d3 | |
parent | 4b7b0f06b459aa2bad371f26576a9e0388795553 (diff) | |
download | cpython-7efa3b8242771f5e63ffaab7bd184e1a5c12c429.zip cpython-7efa3b8242771f5e63ffaab7bd184e1a5c12c429.tar.gz cpython-7efa3b8242771f5e63ffaab7bd184e1a5c12c429.tar.bz2 |
Close #13126: "Simplify" FASTSEARCH() code to help the compiler to emit more
efficient machine code. Patch written by Antoine Pitrou.
Without this change, str.find() was 10% slower than str.rfind() in the worst
case.
-rw-r--r-- | Objects/stringlib/fastsearch.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Objects/stringlib/fastsearch.h b/Objects/stringlib/fastsearch.h index 55ac77d..cd7cac4 100644 --- a/Objects/stringlib/fastsearch.h +++ b/Objects/stringlib/fastsearch.h @@ -142,6 +142,8 @@ FASTSEARCH(const STRINGLIB_CHAR* s, Py_ssize_t n, mask = 0; if (mode != FAST_RSEARCH) { + const STRINGLIB_CHAR *ss = s + m - 1; + const STRINGLIB_CHAR *pp = p + m - 1; /* create compressed boyer-moore delta 1 table */ @@ -156,7 +158,7 @@ FASTSEARCH(const STRINGLIB_CHAR* s, Py_ssize_t n, for (i = 0; i <= w; i++) { /* note: using mlast in the skip path slows things down on x86 */ - if (s[i+m-1] == p[m-1]) { + if (ss[i] == pp[0]) { /* candidate match */ for (j = 0; j < mlast; j++) if (s[i+j] != p[j]) @@ -172,13 +174,13 @@ FASTSEARCH(const STRINGLIB_CHAR* s, Py_ssize_t n, continue; } /* miss: check if next character is part of pattern */ - if (!STRINGLIB_BLOOM(mask, s[i+m])) + if (!STRINGLIB_BLOOM(mask, ss[i+1])) i = i + m; else i = i + skip; } else { /* skip: check if next character is part of pattern */ - if (!STRINGLIB_BLOOM(mask, s[i+m])) + if (!STRINGLIB_BLOOM(mask, ss[i+1])) i = i + m; } } |