diff options
author | Fred Drake <fdrake@acm.org> | 2000-06-20 15:47:54 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2000-06-20 15:47:54 (GMT) |
commit | 396f6e0d6ae414c4bdfbd428da5d64700dcfabf8 (patch) | |
tree | f8d71f751e759991f79839abb2357f4b0bf4daa5 /Objects/stringobject.c | |
parent | 440d89823020b71d7659fcd357c24549ce815b4c (diff) | |
download | cpython-396f6e0d6ae414c4bdfbd428da5d64700dcfabf8.zip cpython-396f6e0d6ae414c4bdfbd428da5d64700dcfabf8.tar.gz cpython-396f6e0d6ae414c4bdfbd428da5d64700dcfabf8.tar.bz2 |
Fredrik Lundh <effbot@telia.com>:
Simplify find code; this is a performance improvement on at least some
platforms.
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index a254019..10b43e4 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -651,7 +651,7 @@ string_split(self, args) i = j = 0; while (i+n <= len) { - if (s[i] == sub[0] && (n == 1 || memcmp(s+i, sub, n) == 0)) { + if (s[i] == sub[0] && memcmp(s+i, sub, n) == 0) { if (maxsplit-- <= 0) break; item = PyString_FromStringAndSize(s+j, (int)(i-j)); @@ -852,8 +852,7 @@ string_find_internal(self, args, dir) return (long)i; last -= n; for (; i <= last; ++i) - if (s[i] == sub[0] && - (n == 1 || memcmp(&s[i+1], &sub[1], n-1) == 0)) + if (s[i] == sub[0] && memcmp(&s[i], sub, n) == 0) return (long)i; } else { @@ -862,8 +861,7 @@ string_find_internal(self, args, dir) if (n == 0 && i <= last) return (long)last; for (j = last-n; j >= i; --j) - if (s[j] == sub[0] && - (n == 1 || memcmp(&s[j+1], &sub[1], n-1) == 0)) + if (s[j] == sub[0] && memcmp(&s[j], sub, n) == 0) return (long)j; } @@ -1415,9 +1413,7 @@ mymemfind(mem, len, pat, pat_len) len -= pat_len; for (ii = 0; ii <= len; ii++) { - if (mem[ii] == pat[0] && - (pat_len == 1 || - memcmp(&mem[ii+1], &pat[1], pat_len-1) == 0)) { + if (mem[ii] == pat[0] && memcmp(&mem[ii], pat, pat_len) == 0) { return ii; } } |