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

Unified Diff: src/heap.cc

Issue 6536: Rolled back hash calculation during flattening (Closed)
Patch Set: Created 12 years, 2 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 34201996b03357bd0c318ff29ccf6a6c44ae96c4..9029819fd18c864937c5dd8a6ecd394ce694da97 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -1400,6 +1400,10 @@ Object* Heap::AllocateSlicedString(String* buffer, int start, int end) {
Object* Heap::AllocateSubString(String* buffer, int start, int end) {
int length = end - start;
+ if (length == 1) {
+ return Heap::LookupSingleCharacterStringFromCode(buffer->Get(start));
+ }
+
// Make an attempt to flatten the buffer to reduce access time.
buffer->TryFlatten();
@@ -1410,9 +1414,19 @@ Object* Heap::AllocateSubString(String* buffer, int start, int end) {
// Copy the characters into the new object.
String* string_result = String::cast(result);
- for (int i = 0; i < length; i++) {
- string_result->Set(i, buffer->Get(start + i));
+ StringHasher hasher(length);
+ int i = 0;
+ for (; i < length && hasher.is_array_index(); i++) {
+ uc32 c = buffer->Get(start + i);
+ hasher.AddCharacter(c);
+ string_result->Set(i, c);
+ }
+ for (; i < length; i++) {
+ uc32 c = buffer->Get(start + i);
+ hasher.AddCharacterNoIndex(c);
+ string_result->Set(i, c);
}
+ string_result->set_length_field(hasher.GetHashField());
return result;
}
« 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