From a68be7629bc957d18aabcd55c53943d74db236c9 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Tue, 22 Apr 2014 11:19:27 +0000 Subject: [PATCH] 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 --- src/factory.cc | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/factory.cc b/src/factory.cc index 569849c..389789f 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -532,6 +532,8 @@ Handle Factory::NewProperSubString(Handle str, #endif ASSERT(begin > 0 || end < str->length()); + str = String::Flatten(str); + int length = end - begin; if (length <= 0) return empty_string(); if (length == 1) { @@ -566,28 +568,10 @@ Handle Factory::NewProperSubString(Handle str, int offset = begin; - while (str->IsConsString()) { - Handle cons = Handle::cast(str); - int split = cons->first()->length(); - if (split <= offset) { - // Slice is fully contained in the second part. - str = Handle(cons->second(), isolate()); - offset -= split; // Adjust for offset. - continue; - } else if (offset + length <= split) { - // Slice is fully contained in the first part. - str = Handle(cons->first(), isolate()); - continue; - } - break; - } - if (str->IsSlicedString()) { Handle slice = Handle::cast(str); str = Handle(slice->parent(), isolate()); offset += slice->offset(); - } else { - str = String::Flatten(str); } ASSERT(str->IsSeqString() || str->IsExternalString()); -- 2.7.4