Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: src/runtime.cc

Issue 2858033: Fix Chromium issue 47824. (Closed)
Patch Set: Addressed review comments Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/regexp-macro-assembler.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index a0f26fc240f0cca8db1fcf67ca9515ce4f3ccf26..22e80b33e0bbe253cd3b563619550cdf4c1920f9 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -2782,13 +2782,17 @@ int Runtime::StringMatch(Handle<String> sub,
// algorithm is unnecessary overhead.
if (pattern_length == 1) {
AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
- if (sub->IsAsciiRepresentation()) {
+ String* seq_sub = *sub;
+ if (seq_sub->IsConsString()) {
+ seq_sub = ConsString::cast(seq_sub)->first();
+ }
+ if (seq_sub->IsAsciiRepresentation()) {
uc16 pchar = pat->Get(0);
if (pchar > String::kMaxAsciiCharCode) {
return -1;
}
Vector<const char> ascii_vector =
- sub->ToAsciiVector().SubVector(start_index, subject_length);
+ seq_sub->ToAsciiVector().SubVector(start_index, subject_length);
const void* pos = memchr(ascii_vector.start(),
static_cast<const char>(pchar),
static_cast<size_t>(ascii_vector.length()));
@@ -2798,7 +2802,9 @@ int Runtime::StringMatch(Handle<String> sub,
return static_cast<int>(reinterpret_cast<const char*>(pos)
- ascii_vector.start() + start_index);
}
- return SingleCharIndexOf(sub->ToUC16Vector(), pat->Get(0), start_index);
+ return SingleCharIndexOf(seq_sub->ToUC16Vector(),
+ pat->Get(0),
+ start_index);
}
if (!pat->IsFlat()) {
@@ -2806,19 +2812,29 @@ int Runtime::StringMatch(Handle<String> sub,
}
AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
+ // Extract flattened substrings of cons strings before determining asciiness.
+ String* seq_sub = *sub;
+ if (seq_sub->IsConsString()) {
+ seq_sub = ConsString::cast(seq_sub)->first();
+ }
+ String* seq_pat = *pat;
+ if (seq_pat->IsConsString()) {
+ seq_pat = ConsString::cast(seq_pat)->first();
+ }
+
// dispatch on type of strings
- if (pat->IsAsciiRepresentation()) {
- Vector<const char> pat_vector = pat->ToAsciiVector();
- if (sub->IsAsciiRepresentation()) {
- return StringSearch(sub->ToAsciiVector(), pat_vector, start_index);
+ if (seq_pat->IsAsciiRepresentation()) {
+ Vector<const char> pat_vector = seq_pat->ToAsciiVector();
+ if (seq_sub->IsAsciiRepresentation()) {
+ return StringSearch(seq_sub->ToAsciiVector(), pat_vector, start_index);
}
- return StringSearch(sub->ToUC16Vector(), pat_vector, start_index);
+ return StringSearch(seq_sub->ToUC16Vector(), pat_vector, start_index);
}
- Vector<const uc16> pat_vector = pat->ToUC16Vector();
- if (sub->IsAsciiRepresentation()) {
- return StringSearch(sub->ToAsciiVector(), pat_vector, start_index);
+ Vector<const uc16> pat_vector = seq_pat->ToUC16Vector();
+ if (seq_sub->IsAsciiRepresentation()) {
+ return StringSearch(seq_sub->ToAsciiVector(), pat_vector, start_index);
}
- return StringSearch(sub->ToUC16Vector(), pat_vector, start_index);
+ return StringSearch(seq_sub->ToUC16Vector(), pat_vector, start_index);
}
« no previous file with comments | « src/regexp-macro-assembler.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698