From: sandholm@chromium.org Date: Wed, 8 Sep 2010 11:05:54 +0000 (+0000) Subject: Store pattern.length() in a local. X-Git-Tag: upstream/4.7.83~21230 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3684dc4d8873371dcf421ec69cc68d6dc9ffabca;p=platform%2Fupstream%2Fv8.git Store pattern.length() in a local. Review URL: http://codereview.chromium.org/3300020 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5428 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/runtime.cc b/src/runtime.cc index 43a6734..ba477b0 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -2830,15 +2830,16 @@ static int SimpleIndexOf(Vector subject, int idx, bool* complete) { ASSERT(pattern.length() > 1); + int pattern_length = 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 - (pattern_length << 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() - pattern_length; i <= n; i++) { badness++; if (badness > 0) { *complete = false; @@ -2863,8 +2864,8 @@ static int SimpleIndexOf(Vector subject, break; } j++; - } while (j < pattern.length()); - if (j == pattern.length()) { + } while (j < pattern_length); + if (j == pattern_length) { *complete = true; return i; } @@ -2879,8 +2880,9 @@ template static int SimpleIndexOf(Vector subject, Vector pattern, int idx) { + int pattern_length = 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() - pattern_length; i <= n; i++) { if (sizeof(schar) == 1 && sizeof(pchar) == 1) { const schar* pos = reinterpret_cast( memchr(subject.start() + i, @@ -2892,13 +2894,13 @@ static int SimpleIndexOf(Vector subject, if (subject[i] != pattern_first_char) continue; } int j = 1; - while (j < pattern.length()) { + while (j < pattern_length) { if (pattern[j] != subject[i+j]) { break; } j++; } - if (j == pattern.length()) { + if (j == pattern_length) { return i; } } @@ -3042,32 +3044,33 @@ static Object* Runtime_StringIndexOf(Arguments args) { template -static int StringMatchBackwards(Vector sub, - Vector pat, +static int StringMatchBackwards(Vector subject, + Vector pattern, int idx) { - ASSERT(pat.length() >= 1); - ASSERT(idx + pat.length() <= sub.length()); + int pattern_length = pattern.length(); + ASSERT(pattern_length >= 1); + ASSERT(idx + pattern_length <= subject.length()); if (sizeof(schar) == 1 && sizeof(pchar) > 1) { - for (int i = 0; i < pat.length(); i++) { - uc16 c = pat[i]; + for (int i = 0; i < pattern_length; i++) { + uc16 c = pattern[i]; if (c > String::kMaxAsciiCharCode) { return -1; } } } - pchar pattern_first_char = pat[0]; + pchar pattern_first_char = pattern[0]; for (int i = idx; i >= 0; i--) { - if (sub[i] != pattern_first_char) continue; + if (subject[i] != pattern_first_char) continue; int j = 1; - while (j < pat.length()) { - if (pat[j] != sub[i+j]) { + while (j < pattern_length) { + if (pattern[j] != subject[i+j]) { break; } j++; } - if (j == pat.length()) { + if (j == pattern_length) { return i; } }