Commit a68be762 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Do not avoid flattening cons string when creating a string slice.

R=ulan@chromium.org
BUG=364656
LOG=N

Review URL: https://codereview.chromium.org/247093002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20882 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9437b59a
...@@ -532,6 +532,8 @@ Handle<String> Factory::NewProperSubString(Handle<String> str, ...@@ -532,6 +532,8 @@ Handle<String> Factory::NewProperSubString(Handle<String> str,
#endif #endif
ASSERT(begin > 0 || end < str->length()); ASSERT(begin > 0 || end < str->length());
str = String::Flatten(str);
int length = end - begin; int length = end - begin;
if (length <= 0) return empty_string(); if (length <= 0) return empty_string();
if (length == 1) { if (length == 1) {
...@@ -566,28 +568,10 @@ Handle<String> Factory::NewProperSubString(Handle<String> str, ...@@ -566,28 +568,10 @@ Handle<String> Factory::NewProperSubString(Handle<String> str,
int offset = begin; int offset = begin;
while (str->IsConsString()) {
Handle<ConsString> cons = Handle<ConsString>::cast(str);
int split = cons->first()->length();
if (split <= offset) {
// Slice is fully contained in the second part.
str = Handle<String>(cons->second(), isolate());
offset -= split; // Adjust for offset.
continue;
} else if (offset + length <= split) {
// Slice is fully contained in the first part.
str = Handle<String>(cons->first(), isolate());
continue;
}
break;
}
if (str->IsSlicedString()) { if (str->IsSlicedString()) {
Handle<SlicedString> slice = Handle<SlicedString>::cast(str); Handle<SlicedString> slice = Handle<SlicedString>::cast(str);
str = Handle<String>(slice->parent(), isolate()); str = Handle<String>(slice->parent(), isolate());
offset += slice->offset(); offset += slice->offset();
} else {
str = String::Flatten(str);
} }
ASSERT(str->IsSeqString() || str->IsExternalString()); ASSERT(str->IsSeqString() || str->IsExternalString());
......
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