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

Unified Diff: src/heap.cc

Issue 140953002: Refactor string internalization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add virtual for real Created 6 years, 11 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 | « src/heap.h ('k') | 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 5e3d75909d6053fea2f9dea5aabc5520fb9e5223..5c6eb18c5d0972f48636c847832b600eb5e64a55 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -3858,8 +3858,8 @@ MaybeObject* Heap::LookupSingleCharacterStringFromCode(uint16_t code) {
uint8_t buffer[1];
buffer[0] = static_cast<uint8_t>(code);
Object* result;
- MaybeObject* maybe_result =
- InternalizeOneByteString(Vector<const uint8_t>(buffer, 1));
+ OneByteStringKey key(Vector<const uint8_t>(buffer, 1), HashSeed());
+ MaybeObject* maybe_result = InternalizeStringWithKey(&key);
if (!maybe_result->ToObject(&result)) return maybe_result;
single_character_string_cache()->set(code, result);
@@ -4742,8 +4742,9 @@ MaybeObject* Heap::ReinitializeJSReceiver(
SharedFunctionInfo* shared = NULL;
if (type == JS_FUNCTION_TYPE) {
String* name;
- maybe =
- InternalizeOneByteString(STATIC_ASCII_VECTOR("<freezing call trap>"));
+ OneByteStringKey key(STATIC_ASCII_VECTOR("<freezing call trap>"),
+ HashSeed());
+ maybe = InternalizeStringWithKey(&key);
if (!maybe->To<String>(&name)) return maybe;
maybe = AllocateSharedFunctionInfo(name);
if (!maybe->To<SharedFunctionInfo>(&shared)) return maybe;
@@ -5876,45 +5877,17 @@ void Heap::Verify() {
MaybeObject* Heap::InternalizeUtf8String(Vector<const char> string) {
- Object* result = NULL;
- Object* new_table;
- { MaybeObject* maybe_new_table =
- string_table()->LookupUtf8String(string, &result);
- if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
- }
- // Can't use set_string_table because StringTable::cast knows that
- // StringTable is a singleton and checks for identity.
- roots_[kStringTableRootIndex] = new_table;
- ASSERT(result != NULL);
- return result;
-}
-
-
-MaybeObject* Heap::InternalizeOneByteString(Vector<const uint8_t> string) {
- Object* result = NULL;
- Object* new_table;
- { MaybeObject* maybe_new_table =
- string_table()->LookupOneByteString(string, &result);
- if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
- }
- // Can't use set_string_table because StringTable::cast knows that
- // StringTable is a singleton and checks for identity.
- roots_[kStringTableRootIndex] = new_table;
- ASSERT(result != NULL);
- return result;
+ Utf8StringKey key(string, HashSeed());
+ return InternalizeStringWithKey(&key);
}
-MaybeObject* Heap::InternalizeOneByteString(Handle<SeqOneByteString> string,
- int from,
- int length) {
+MaybeObject* Heap::InternalizeString(String* string) {
+ if (string->IsInternalizedString()) return string;
Object* result = NULL;
Object* new_table;
{ MaybeObject* maybe_new_table =
- string_table()->LookupSubStringOneByteString(string,
- from,
- length,
- &result);
+ string_table()->LookupString(string, &result);
if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
}
// Can't use set_string_table because StringTable::cast knows that
@@ -5925,27 +5898,20 @@ MaybeObject* Heap::InternalizeOneByteString(Handle<SeqOneByteString> string,
}
-MaybeObject* Heap::InternalizeTwoByteString(Vector<const uc16> string) {
- Object* result = NULL;
- Object* new_table;
- { MaybeObject* maybe_new_table =
- string_table()->LookupTwoByteString(string, &result);
- if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
+bool Heap::InternalizeStringIfExists(String* string, String** result) {
+ if (string->IsInternalizedString()) {
+ *result = string;
+ return true;
}
- // Can't use set_string_table because StringTable::cast knows that
- // StringTable is a singleton and checks for identity.
- roots_[kStringTableRootIndex] = new_table;
- ASSERT(result != NULL);
- return result;
+ return string_table()->LookupStringIfExists(string, result);
}
-MaybeObject* Heap::InternalizeString(String* string) {
- if (string->IsInternalizedString()) return string;
+MaybeObject* Heap::InternalizeStringWithKey(HashTableKey* key) {
Object* result = NULL;
Object* new_table;
{ MaybeObject* maybe_new_table =
- string_table()->LookupString(string, &result);
+ string_table()->LookupKey(key, &result);
if (!maybe_new_table->ToObject(&new_table)) return maybe_new_table;
}
// Can't use set_string_table because StringTable::cast knows that
@@ -5956,15 +5922,6 @@ MaybeObject* Heap::InternalizeString(String* string) {
}
-bool Heap::InternalizeStringIfExists(String* string, String** result) {
- if (string->IsInternalizedString()) {
- *result = string;
- return true;
- }
- return string_table()->LookupStringIfExists(string, result);
-}
-
-
void Heap::ZapFromSpace() {
NewSpacePageIterator it(new_space_.FromSpaceStart(),
new_space_.FromSpaceEnd());
« no previous file with comments | « src/heap.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698