Index: src/jsregexp.cc |
diff --git a/src/jsregexp.cc b/src/jsregexp.cc |
index bc47df8f23c0017fce39e41813007dec4a0952a1..561a9f8e82f1c7aff2939d72ac9e707efd449550 100644 |
--- a/src/jsregexp.cc |
+++ b/src/jsregexp.cc |
@@ -234,11 +234,12 @@ Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, |
ASSERT(0 <= index); |
ASSERT(index <= subject->length()); |
- if (!subject->IsFlat()) FlattenString(subject); |
+ if (!subject->IsFlatAndTruncated()) FlattenOrTruncateString(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* seq_sub = StringShape(*subject).IsIndirect() |
+ ? subject->GetIndirect() |
+ : *subject; |
String* needle = String::cast(re->DataAt(JSRegExp::kAtomPatternIndex)); |
int needle_len = needle->length(); |
@@ -355,10 +356,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,17 +440,15 @@ void RegExpImpl::IrregexpInitialize(Handle<JSRegExp> re, |
int RegExpImpl::IrregexpPrepare(Handle<JSRegExp> regexp, |
Handle<String> subject) { |
- if (!subject->IsFlat()) { |
- FlattenString(subject); |
- } |
+ if (!subject->IsFlatAndTruncated()) FlattenOrTruncateString(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(); |
- } |
+ String* sequential_string = StringShape(*subject).IsIndirect() |
+ ? subject->GetIndirect() |
+ : *subject; |
is_ascii = sequential_string->IsAsciiRepresentation(); |
} |
if (!EnsureCompiledIrregexp(regexp, is_ascii)) { |
@@ -482,9 +478,9 @@ 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); |
+ // A flat ASCII indirect string might actually be two-byte. |
+ if (StringShape(*subject).IsIndirect()) { |
+ subject = Handle<String>(subject->GetIndirect(), isolate); |
} |
#ifndef V8_INTERPRETED_REGEXP |