Reviewers: Erik Corry, Description: Store pattern.length() in a local.
Please review this at http://codereview.chromium.org/3300020/show SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: M src/runtime.cc Index: src/runtime.cc =================================================================== --- src/runtime.cc (revision 5402) +++ src/runtime.cc (working copy) @@ -2830,15 +2830,16 @@ int idx, bool* complete) { ASSERT(pattern.length() > 1); + int plen = pattern.length(); // Badness is a count of how much work we have done. When we have // done enough work we decide it's probably worth switching to a better // algorithm. - int badness = -10 - (pattern.length() << 2); + int badness = -10 - (plen << 2); // We know our pattern is at least 2 characters, we cache the first so // the common case of the first character not matching is faster. pchar pattern_first_char = pattern[0]; - for (int i = idx, n = subject.length() - pattern.length(); i <= n; i++) { + for (int i = idx, n = subject.length() - plen; i <= n; i++) { badness++; if (badness > 0) { *complete = false; @@ -2863,8 +2864,8 @@ break; } j++; - } while (j < pattern.length()); - if (j == pattern.length()) { + } while (j < plen); + if (j == plen) { *complete = true; return i; } @@ -2879,8 +2880,9 @@ static int SimpleIndexOf(Vector<const schar> subject, Vector<const pchar> pattern, int idx) { + int plen = pattern.length(); pchar pattern_first_char = pattern[0]; - for (int i = idx, n = subject.length() - pattern.length(); i <= n; i++) { + for (int i = idx, n = subject.length() - plen; i <= n; i++) { if (sizeof(schar) == 1 && sizeof(pchar) == 1) { const schar* pos = reinterpret_cast<const schar*>( memchr(subject.start() + i, @@ -2892,13 +2894,13 @@ if (subject[i] != pattern_first_char) continue; } int j = 1; - while (j < pattern.length()) { + while (j < plen) { if (pattern[j] != subject[i+j]) { break; } j++; } - if (j == pattern.length()) { + if (j == plen) { return i; } } @@ -3045,11 +3047,12 @@ static int StringMatchBackwards(Vector<const schar> sub, Vector<const pchar> pat, int idx) { - ASSERT(pat.length() >= 1); - ASSERT(idx + pat.length() <= sub.length()); + int plen = pat.length(); + ASSERT(plen >= 1); + ASSERT(idx + plen <= sub.length()); if (sizeof(schar) == 1 && sizeof(pchar) > 1) { - for (int i = 0; i < pat.length(); i++) { + for (int i = 0; i < plen; i++) { uc16 c = pat[i]; if (c > String::kMaxAsciiCharCode) { return -1; @@ -3061,13 +3064,13 @@ for (int i = idx; i >= 0; i--) { if (sub[i] != pattern_first_char) continue; int j = 1; - while (j < pat.length()) { + while (j < plen) { if (pat[j] != sub[i+j]) { break; } j++; } - if (j == pat.length()) { + if (j == plen) { return i; } } -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev
