Reviewers: Benedikt Meurer,

Description:
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.

[email protected]
BUG=323041

Please review this at https://codereview.chromium.org/88143002/
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index f28c9260b9d8ebc211381ed971db3bbfaad88977..cf9d6c709ee489f0658196d3244c96c12e822c1c 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<const uint8_t> string,
-                                           PretenureFlag pretenure) {
+                                             PretenureFlag pretenure) {
   int length = string.length();
   if (length == 1) {
     return Heap::LookupSingleCharacterStringFromCode(string[0]);
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 67e5e9e3dfaf84a7d2c2c57ab51c41cc7a408105..76ca766055af5fcb2fdee4d30b33da23e938328a 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);
 }



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to