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

Unified Diff: src/heap.cc

Issue 1444001: Some string optimizations: (Closed)
Patch Set: Review fix. Created 10 years, 9 months 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 | « no previous file | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index 1f1599a79bf6c8f0f0a8482a082e1c32807e6fb2..5421dcc1956af1af53b4ce45057893232a643e06 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -1961,8 +1961,9 @@ Object* Heap::AllocateConsString(String* first, String* second) {
return MakeOrFindTwoCharacterString(c1, c2);
}
- bool is_ascii = first->IsAsciiRepresentation()
- && second->IsAsciiRepresentation();
+ bool first_is_ascii = first->IsAsciiRepresentation();
+ bool second_is_ascii = second->IsAsciiRepresentation();
+ bool is_ascii = first_is_ascii && second_is_ascii;
// Make sure that an out of memory exception is thrown if the length
// of the new cons string is too large.
@@ -1997,6 +1998,25 @@ Object* Heap::AllocateConsString(String* first, String* second) {
for (int i = 0; i < second_length; i++) *dest++ = src[i];
return result;
} else {
+ // For short external two-byte strings we check whether they can
+ // be represented using ascii.
+ if (!first_is_ascii) {
+ first_is_ascii = first->IsExternalTwoByteStringWithAsciiChars();
+ }
+ if (first_is_ascii && !second_is_ascii) {
+ second_is_ascii = second->IsExternalTwoByteStringWithAsciiChars();
+ }
+ if (first_is_ascii && second_is_ascii) {
+ Object* result = AllocateRawAsciiString(length);
+ if (result->IsFailure()) return result;
+ // Copy the characters into the new object.
+ char* dest = SeqAsciiString::cast(result)->GetChars();
+ String::WriteToFlat(first, dest, 0, first_length);
+ String::WriteToFlat(second, dest + first_length, 0, second_length);
+ Counters::string_add_runtime_ext_to_ascii.Increment();
+ return result;
+ }
+
Object* result = AllocateRawTwoByteString(length);
if (result->IsFailure()) return result;
// Copy the characters into the new object.
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698