Chromium Code Reviews| Index: src/jsregexp.cc |
| diff --git a/src/jsregexp.cc b/src/jsregexp.cc |
| index bc47df8f23c0017fce39e41813007dec4a0952a1..0e2afb5f106031de4f0b6b3ae22e75a7924f203e 100644 |
| --- a/src/jsregexp.cc |
| +++ b/src/jsregexp.cc |
| @@ -237,8 +237,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. |
|
Vitaly Repeshko
2011/08/17 19:20:23
Update the comment.
|
| - 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(); |
| @@ -251,20 +252,20 @@ Handle<Object> RegExpImpl::AtomExec(Handle<JSRegExp> re, |
| index = (needle->IsAsciiRepresentation() |
| ? (seq_sub->IsAsciiRepresentation() |
| ? SearchString(isolate, |
| - seq_sub->ToAsciiVector(), |
| + subject->ToAsciiVector(), |
|
Vitaly Repeshko
2011/08/17 19:20:23
To{Ascii,UC16}Vector won't work in case an indirec
Yang
2011/08/18 12:17:32
I solved this by changing the assertion in both To
|
| needle->ToAsciiVector(), |
| index) |
| : SearchString(isolate, |
| - seq_sub->ToUC16Vector(), |
| + subject->ToUC16Vector(), |
| needle->ToAsciiVector(), |
| index)) |
| : (seq_sub->IsAsciiRepresentation() |
| ? 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 +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->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(); |
| - } |
| + String* sequential_string = StringShape(*subject).IsIndirect() |
| + ? subject->GetIndirect() |
| + : *subject; |
| is_ascii = sequential_string->IsAsciiRepresentation(); |
| } |
| if (!EnsureCompiledIrregexp(regexp, is_ascii)) { |
| @@ -482,15 +478,16 @@ 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); |
|
Vitaly Repeshko
2011/08/17 19:20:23
This unwrapping didn't help the code called below
|
| - } |
| - |
| #ifndef V8_INTERPRETED_REGEXP |
| ASSERT(output.length() >= (IrregexpNumberOfCaptures(*irregexp) + 1) * 2); |
| do { |
| - bool is_ascii = subject->IsAsciiRepresentation(); |
| + // A flat ASCII indirect string might actually be two-byte. |
| + bool is_ascii; |
| + if (StringShape(*subject).IsIndirect()) { |
| + is_ascii = subject->GetIndirect()->IsAsciiRepresentation(); |
| + } else { |
| + is_ascii = subject->IsAsciiRepresentation(); |
| + } |
| EnsureCompiledIrregexp(regexp, is_ascii); |
| Handle<Code> code(IrregexpNativeCode(*irregexp, is_ascii), isolate); |
| NativeRegExpMacroAssembler::Result res = |