From 4240cd2506161a7d169f421f6258405aac16b163 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Tue, 26 Nov 2013 14:21:46 +0000 Subject: [PATCH] Flatten cons string for single character substrings. For substrings of non-flat cons strings, we bail out to runtime. For single character substrings, we forget to flatten it. This causes successive bailouts. R=bmeurer@chromium.org BUG=323041 LOG=Y Review URL: https://codereview.chromium.org/88173002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18081 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/heap.cc | 12 +++++++----- src/runtime.cc | 4 ---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/heap.cc b/src/heap.cc index f28c9260b9..cf9d6c709e 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -3968,7 +3968,12 @@ MaybeObject* Heap::AllocateSubString(String* buffer, int length = end - start; if (length <= 0) { return empty_string(); - } else if (length == 1) { + } + + // Make an attempt to flatten the buffer to reduce access time. + buffer = buffer->TryFlattenGetString(); + + if (length == 1) { return LookupSingleCharacterStringFromCode(buffer->Get(start)); } else if (length == 2) { // Optimization for 2-byte strings often used as keys in a decompression @@ -3979,9 +3984,6 @@ MaybeObject* Heap::AllocateSubString(String* buffer, return MakeOrFindTwoCharacterString(this, c1, c2); } - // Make an attempt to flatten the buffer to reduce access time. - buffer = buffer->TryFlattenGetString(); - if (!FLAG_string_slices || !buffer->IsFlat() || length < SlicedString::kMinLength || @@ -4981,7 +4983,7 @@ MaybeObject* Heap::ReinitializeJSGlobalProxy(JSFunction* constructor, MaybeObject* Heap::AllocateStringFromOneByte(Vector string, - PretenureFlag pretenure) { + PretenureFlag pretenure) { int length = string.length(); if (length == 1) { return Heap::LookupSingleCharacterStringFromCode(string[0]); diff --git a/src/runtime.cc b/src/runtime.cc index fbe4426a28..a8b7024b65 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -4463,10 +4463,6 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SubString) { RUNTIME_ASSERT(start >= 0); RUNTIME_ASSERT(end <= value->length()); isolate->counters()->sub_string_runtime()->Increment(); - if (end - start == 1) { - return isolate->heap()->LookupSingleCharacterStringFromCode( - value->Get(start)); - } return value->SubString(start, end); }