Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1063)

Unified Diff: test/cctest/test-strings.cc

Issue 2489273002: Fast-path in SlowFlatten for ConsStrings with empty first part (Closed)
Patch Set: Ensure string length does not change in test Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-strings.cc
diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc
index 9793ae7f18fdd51dbef9d26e3566963b75247cb4..80c8f92ac431ef8d0a714a3565db57a94d97dbd2 100644
--- a/test/cctest/test-strings.cc
+++ b/test/cctest/test-strings.cc
@@ -600,6 +600,42 @@ TEST(Traverse) {
printf("18\n");
}
+TEST(ConsStringWithEmptyFirstFlatten) {
+ printf("ConsStringWithEmptyFirstFlatten\n");
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
+ Isolate* isolate = CcTest::i_isolate();
+
+ i::Handle<i::String> initial_fst =
+ isolate->factory()->NewStringFromAsciiChecked("fst012345");
+ i::Handle<i::String> initial_snd =
+ isolate->factory()->NewStringFromAsciiChecked("snd012345");
+ i::Handle<i::String> str = isolate->factory()
+ ->NewConsString(initial_fst, initial_snd)
+ .ToHandleChecked();
+ CHECK(str->IsConsString());
+ auto cons = i::Handle<i::ConsString>::cast(str);
+
+ const int initial_length = cons->length();
+
+ // set_first / set_second does not update the length (which the heap verifier
+ // checks), so we need to ensure the length stays the same.
+
+ i::Handle<i::String> new_fst = isolate->factory()->empty_string();
+ i::Handle<i::String> new_snd =
+ isolate->factory()->NewStringFromAsciiChecked("snd012345012345678");
+ cons->set_first(*new_fst);
+ cons->set_second(*new_snd);
+ CHECK(!cons->IsFlat());
+ CHECK_EQ(initial_length, new_fst->length() + new_snd->length());
+ CHECK_EQ(initial_length, cons->length());
+
+ // Make sure Flatten doesn't alloc a new string.
+ DisallowHeapAllocation no_alloc;
+ i::Handle<i::String> flat = i::String::Flatten(cons);
+ CHECK(flat->IsFlat());
+ CHECK_EQ(initial_length, flat->length());
+}
static void VerifyCharacterStream(
String* flat_string, String* cons_string) {
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698