Index: src/jsregexp.cc |
diff --git a/src/jsregexp.cc b/src/jsregexp.cc |
index bc47df8f23c0017fce39e41813007dec4a0952a1..193b1b504834b1058f6dce784d89c7323c06f942 100644 |
--- a/src/jsregexp.cc |
+++ b/src/jsregexp.cc |
@@ -236,11 +236,9 @@ Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, |
if (!subject->IsFlat()) FlattenString(subject); |
AssertNoAllocation no_heap_allocation; // ensure vectors stay valid |
- // Extract flattened substrings of cons strings before determining asciiness. |
- String* seq_sub = *subject; |
- if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first(); |
String* needle = String::cast(re->DataAt(JSRegExp::kAtomPatternIndex)); |
+ ASSERT(StringShape(needle).IsSequential()); |
int needle_len = needle->length(); |
if (needle_len != 0) { |
@@ -249,22 +247,22 @@ Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, |
// dispatch on type of strings |
index = (needle->IsAsciiRepresentation() |
- ? (seq_sub->IsAsciiRepresentation() |
+ ? (subject->IsAsciiRepresentationUnderneath() |
? SearchString(isolate, |
- seq_sub->ToAsciiVector(), |
+ subject->ToAsciiVector(), |
needle->ToAsciiVector(), |
index) |
: SearchString(isolate, |
- seq_sub->ToUC16Vector(), |
+ subject->ToUC16Vector(), |
needle->ToAsciiVector(), |
index)) |
- : (seq_sub->IsAsciiRepresentation() |
+ : (subject->IsAsciiRepresentationUnderneath() |
? SearchString(isolate, |
- seq_sub->ToAsciiVector(), |
+ subject->ToAsciiVector(), |
needle->ToUC16Vector(), |
index) |
: SearchString(isolate, |
- seq_sub->ToUC16Vector(), |
+ subject->ToUC16Vector(), |
needle->ToUC16Vector(), |
index))); |
if (index == -1) return FACTORY->null_value(); |
@@ -355,10 +353,7 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_ascii) { |
JSRegExp::Flags flags = re->GetFlags(); |
Handle<String> pattern(re->Pattern()); |
- if (!pattern->IsFlat()) { |
- FlattenString(pattern); |
- } |
- |
+ if (!pattern->IsFlat()) FlattenString(pattern); |
RegExpCompileData compile_data; |
FlatStringReader reader(isolate, pattern); |
if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), |
@@ -442,22 +437,12 @@ void RegExpImpl::IrregexpInitialize(Handle<JSRegExp> re, |
int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, |
Handle<String> subject) { |
- if (!subject->IsFlat()) { |
- FlattenString(subject); |
- } |
+ if (!subject->IsFlat()) FlattenString(subject); |
+ |
// Check the asciiness of the underlying storage. |
- bool is_ascii; |
- { |
- AssertNoAllocation no_gc; |
- String* sequential_string = *subject; |
- if (subject->IsConsString()) { |
- sequential_string = ConsString::cast(*subject)->first(); |
- } |
- is_ascii = sequential_string->IsAsciiRepresentation(); |
- } |
- if (!EnsureCompiledIrregexp(regexp, is_ascii)) { |
- return -1; |
- } |
+ bool is_ascii = subject->IsAsciiRepresentationUnderneath(); |
+ if (!EnsureCompiledIrregexp(regexp, is_ascii)) return -1; |
+ |
#ifdef V8_INTERPRETED_REGEXP |
// Byte-code regexp needs space allocated for all its registers. |
return IrregexpNumberOfRegisters(FixedArray::cast(regexp->data())); |
@@ -482,15 +467,11 @@ RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce( |
ASSERT(index <= subject->length()); |
ASSERT(subject->IsFlat()); |
- // A flat ASCII string might have a two-byte first part. |
- if (subject->IsConsString()) { |
- subject = Handle<String>(ConsString::cast(*subject)->first(), isolate); |
- } |
+ bool is_ascii = subject->IsAsciiRepresentationUnderneath(); |
#ifndef V8_INTERPRETED_REGEXP |
ASSERT(output.length() >= (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); |
do { |
- bool is_ascii = subject->IsAsciiRepresentation(); |
EnsureCompiledIrregexp(regexp, is_ascii); |
Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii), isolate); |
NativeRegExpMacroAssembler::Result res = |
@@ -518,13 +499,13 @@ RegExpImpl::IrregexpResult RegExpImpl::IrregexpExecOnce( |
// being internal and external, and even between being ASCII and UC16, |
// but the characters are always the same). |
IrregexpPrepare(regexp, subject); |
+ is_ascii = subject->IsAsciiRepresentationUnderneath(); |
} while (true); |
UNREACHABLE(); |
return RE_EXCEPTION; |
#else // V8_INTERPRETED_REGEXP |
ASSERT(output.length() >= IrregexpNumberOfRegisters(*irregexp)); |
- bool is_ascii = subject->IsAsciiRepresentation(); |
// We must have done EnsureCompiledIrregexp, so we can get the number of |
// registers. |
int* register_vector = output.start(); |