Commit 3684dc4d authored by sandholm@chromium.org's avatar sandholm@chromium.org

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
parent dc4898aa
...@@ -2830,15 +2830,16 @@ static int SimpleIndexOf(Vector<const schar> subject, ...@@ -2830,15 +2830,16 @@ static int SimpleIndexOf(Vector<const schar> subject,
int idx, int idx,
bool* complete) { bool* complete) {
ASSERT(pattern.length() > 1); ASSERT(pattern.length() > 1);
int pattern_length = pattern.length();
// Badness is a count of how much work we have done. When we have // 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 // done enough work we decide it's probably worth switching to a better
// algorithm. // 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 // 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. // the common case of the first character not matching is faster.
pchar pattern_first_char = pattern[0]; 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++; badness++;
if (badness > 0) { if (badness > 0) {
*complete = false; *complete = false;
...@@ -2863,8 +2864,8 @@ static int SimpleIndexOf(Vector<const schar> subject, ...@@ -2863,8 +2864,8 @@ static int SimpleIndexOf(Vector<const schar> subject,
break; break;
} }
j++; j++;
} while (j < pattern.length()); } while (j < pattern_length);
if (j == pattern.length()) { if (j == pattern_length) {
*complete = true; *complete = true;
return i; return i;
} }
...@@ -2879,8 +2880,9 @@ template <typename pchar, typename schar> ...@@ -2879,8 +2880,9 @@ template <typename pchar, typename schar>
static int SimpleIndexOf(Vector<const schar> subject, static int SimpleIndexOf(Vector<const schar> subject,
Vector<const pchar> pattern, Vector<const pchar> pattern,
int idx) { int idx) {
int pattern_length = pattern.length();
pchar pattern_first_char = pattern[0]; 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) { if (sizeof(schar) == 1 && sizeof(pchar) == 1) {
const schar* pos = reinterpret_cast<const schar*>( const schar* pos = reinterpret_cast<const schar*>(
memchr(subject.start() + i, memchr(subject.start() + i,
...@@ -2892,13 +2894,13 @@ static int SimpleIndexOf(Vector<const schar> subject, ...@@ -2892,13 +2894,13 @@ static int SimpleIndexOf(Vector<const schar> subject,
if (subject[i] != pattern_first_char) continue; if (subject[i] != pattern_first_char) continue;
} }
int j = 1; int j = 1;
while (j < pattern.length()) { while (j < pattern_length) {
if (pattern[j] != subject[i+j]) { if (pattern[j] != subject[i+j]) {
break; break;
} }
j++; j++;
} }
if (j == pattern.length()) { if (j == pattern_length) {
return i; return i;
} }
} }
...@@ -3042,32 +3044,33 @@ static Object* Runtime_StringIndexOf(Arguments args) { ...@@ -3042,32 +3044,33 @@ static Object* Runtime_StringIndexOf(Arguments args) {
template <typename schar, typename pchar> template <typename schar, typename pchar>
static int StringMatchBackwards(Vector<const schar> sub, static int StringMatchBackwards(Vector<const schar> subject,
Vector<const pchar> pat, Vector<const pchar> pattern,
int idx) { int idx) {
ASSERT(pat.length() >= 1); int pattern_length = pattern.length();
ASSERT(idx + pat.length() <= sub.length()); ASSERT(pattern_length >= 1);
ASSERT(idx + pattern_length <= subject.length());
if (sizeof(schar) == 1 && sizeof(pchar) > 1) { if (sizeof(schar) == 1 && sizeof(pchar) > 1) {
for (int i = 0; i < pat.length(); i++) { for (int i = 0; i < pattern_length; i++) {
uc16 c = pat[i]; uc16 c = pattern[i];
if (c > String::kMaxAsciiCharCode) { if (c > String::kMaxAsciiCharCode) {
return -1; return -1;
} }
} }
} }
pchar pattern_first_char = pat[0]; pchar pattern_first_char = pattern[0];
for (int i = idx; i >= 0; i--) { for (int i = idx; i >= 0; i--) {
if (sub[i] != pattern_first_char) continue; if (subject[i] != pattern_first_char) continue;
int j = 1; int j = 1;
while (j < pat.length()) { while (j < pattern_length) {
if (pat[j] != sub[i+j]) { if (pattern[j] != subject[i+j]) {
break; break;
} }
j++; j++;
} }
if (j == pat.length()) { if (j == pattern_length) {
return i; return i;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment