(original) (raw)

changeset: 83192:c5e2ea9e3aa7 user: Victor Stinner victor.stinner@gmail.com date: Mon Apr 08 00:26:43 2013 +0200 files: Objects/stringlib/fastsearch.h description: 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. diff -r 0437c19cdad0 -r c5e2ea9e3aa7 Objects/stringlib/fastsearch.h --- a/Objects/stringlib/fastsearch.h Sun Apr 07 23:46:52 2013 +0200 +++ b/Objects/stringlib/fastsearch.h Mon Apr 08 00:26:43 2013 +0200 @@ -142,6 +142,8 @@ 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 @@ 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 @@ 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; } } /victor.stinner@gmail.com