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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 Traverse(flat, right_asymmetric); 593 Traverse(flat, right_asymmetric);
594 printf("14\n"); 594 printf("14\n");
595 String::Flatten(symmetric); 595 String::Flatten(symmetric);
596 printf("15\n"); 596 printf("15\n");
597 Traverse(flat, symmetric); 597 Traverse(flat, symmetric);
598 printf("16\n"); 598 printf("16\n");
599 String::Flatten(left_deep_asymmetric); 599 String::Flatten(left_deep_asymmetric);
600 printf("18\n"); 600 printf("18\n");
601 } 601 }
602 602
603 TEST(ConsStringWithEmptyFirstFlatten) {
604 printf("ConsStringWithEmptyFirstFlatten\n");
605 CcTest::InitializeVM();
606 v8::HandleScope scope(CcTest::isolate());
607 Isolate* isolate = CcTest::i_isolate();
608
609 i::Handle<i::String> initial_fst =
610 isolate->factory()->NewStringFromAsciiChecked("fst012345");
611 i::Handle<i::String> initial_snd =
612 isolate->factory()->NewStringFromAsciiChecked("snd012345");
613 i::Handle<i::String> str = isolate->factory()
614 ->NewConsString(initial_fst, initial_snd)
615 .ToHandleChecked();
616 CHECK(str->IsConsString());
617 auto cons = i::Handle<i::ConsString>::cast(str);
618
619 const int initial_length = cons->length();
620
621 // set_first / set_second does not update the length (which the heap verifier
622 // checks), so we need to ensure the length stays the same.
623
624 i::Handle<i::String> new_fst = isolate->factory()->empty_string();
625 i::Handle<i::String> new_snd =
626 isolate->factory()->NewStringFromAsciiChecked("snd012345012345678");
627 cons->set_first(*new_fst);
628 cons->set_second(*new_snd);
629 CHECK(!cons->IsFlat());
630 CHECK_EQ(initial_length, new_fst->length() + new_snd->length());
631 CHECK_EQ(initial_length, cons->length());
632
633 // Make sure Flatten doesn't alloc a new string.
634 DisallowHeapAllocation no_alloc;
635 i::Handle<i::String> flat = i::String::Flatten(cons);
636 CHECK(flat->IsFlat());
637 CHECK_EQ(initial_length, flat->length());
638 }
603 639
604 static void VerifyCharacterStream( 640 static void VerifyCharacterStream(
605 String* flat_string, String* cons_string) { 641 String* flat_string, String* cons_string) {
606 // Do not want to test ConString traversal on flat string. 642 // Do not want to test ConString traversal on flat string.
607 CHECK(flat_string->IsFlat() && !flat_string->IsConsString()); 643 CHECK(flat_string->IsFlat() && !flat_string->IsConsString());
608 CHECK(cons_string->IsConsString()); 644 CHECK(cons_string->IsConsString());
609 // TODO(dcarney) Test stream reset as well. 645 // TODO(dcarney) Test stream reset as well.
610 int length = flat_string->length(); 646 int length = flat_string->length();
611 // Iterate start search in multiple places in the string. 647 // Iterate start search in multiple places in the string.
612 int outer_iterations = length > 20 ? 20 : length; 648 int outer_iterations = length > 20 ? 20 : length;
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 } 1601 }
1566 { 1602 {
1567 HandleScope scope(isolate); 1603 HandleScope scope(isolate);
1568 v8::Local<v8::Value> result = CompileRun( 1604 v8::Local<v8::Value> result = CompileRun(
1569 "String.fromCharCode(432, 432, 432, 432, 432, " 1605 "String.fromCharCode(432, 432, 432, 432, 432, "
1570 "432, 432, 432, 432, 432, 432, 432, 432, 432, " 1606 "432, 432, 432, 432, 432, 432, 432, 432, 432, "
1571 "432, 432, 432, 432, 432, 432, 432, 432, 432)"); 1607 "432, 432, 432, 432, 432, 432, 432, 432, 432)");
1572 CHECK(v8::Utils::OpenHandle(*result)->IsSeqTwoByteString()); 1608 CHECK(v8::Utils::OpenHandle(*result)->IsSeqTwoByteString());
1573 } 1609 }
1574 } 1610 }
OLDNEW
« 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