// Numeric strings have a different hash algorithm not known by
// LookupTwoCharsStringIfExists, so we skip this step for such strings.
if (!Between(c1, '0', '9') || !Between(c2, '0', '9')) {
- String* result;
- StringTable* table = isolate->heap()->string_table();
- if (table->LookupTwoCharsStringIfExists(c1, c2, &result)) {
- return handle(result);
+ Handle<String> result;
+ if (StringTable::LookupTwoCharsStringIfExists(isolate, c1, c2).
+ ToHandle(&result)) {
+ return result;
}
}
#endif
-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());
int field_offset) {
DisallowHeapAllocation no_gc;
if (!name->IsUniqueName()) {
- String* internalized_string;
- if (!map->GetIsolate()->heap()->InternalizeStringIfExists(
- String::cast(*name), &internalized_string)) {
+ if (!StringTable::InternalizeStringIfExists(name->GetIsolate(),
+ Handle<String>::cast(name)).
+ ToHandle(&name)) {
return;
}
- name = handle(internalized_string);
}
// This cache is cleared only between mark compact passes, so we expect the
// cache to only contain old space names.
// Maintain marking consistency for IncrementalMarking.
void AdjustLiveBytes(Address address, int by, InvocationMode mode);
- bool InternalizeStringIfExists(String* str, String** result);
-
// Converts the given boolean condition to JavaScript boolean value.
inline Object* ToBoolean(bool condition);
};
-bool StringTable::LookupStringIfExists(String* string, String** result) {
- SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table());
- DisallowHeapAllocation no_alloc;
- // TODO(ishell): Handlify all the callers and remove this scope.
- HandleScope scope(GetIsolate());
- InternalizedStringKey key(handle(string));
- int entry = FindEntry(&key);
+MaybeHandle<String> StringTable::InternalizeStringIfExists(
+ Isolate* isolate,
+ Handle<String> string) {
+ if (string->IsInternalizedString()) {
+ return string;
+ }
+ return LookupStringIfExists(isolate, string);
+}
+
+
+MaybeHandle<String> StringTable::LookupStringIfExists(
+ Isolate* isolate,
+ Handle<String> string) {
+ Handle<StringTable> string_table = isolate->factory()->string_table();
+ InternalizedStringKey key(string);
+ int entry = string_table->FindEntry(&key);
if (entry == kNotFound) {
- return false;
+ return MaybeHandle<String>();
} else {
- *result = String::cast(KeyAt(entry));
+ Handle<String> result(String::cast(string_table->KeyAt(entry)), isolate);
ASSERT(StringShape(*result).IsInternalized());
- return true;
+ return result;
}
}
-bool StringTable::LookupTwoCharsStringIfExists(uint16_t c1,
- uint16_t c2,
- String** result) {
- SLOW_ASSERT(this == HeapObject::cast(this)->GetHeap()->string_table());
- TwoCharHashTableKey key(c1, c2, GetHeap()->HashSeed());
- int entry = FindEntry(&key);
+MaybeHandle<String> StringTable::LookupTwoCharsStringIfExists(
+ Isolate* isolate,
+ uint16_t c1,
+ uint16_t c2) {
+ Handle<StringTable> string_table = isolate->factory()->string_table();
+ TwoCharHashTableKey key(c1, c2, isolate->heap()->HashSeed());
+ int entry = string_table->FindEntry(&key);
if (entry == kNotFound) {
- return false;
+ return MaybeHandle<String>();
} else {
- *result = String::cast(KeyAt(entry));
+ Handle<String> result(String::cast(string_table->KeyAt(entry)), isolate);
ASSERT(StringShape(*result).IsInternalized());
- return true;
+ return result;
}
}
//
// No special elements in the prefix and the element size is 1
// because only the string itself (the key) needs to be stored.
-// TODO(ishell): Make StringTable a singleton class and move
-// Heap::InternalizeStringXX() methods here.
class StringTable: public HashTable<StringTable,
StringTableShape,
HashTableKey*> {
static Handle<String> LookupString(Isolate* isolate, Handle<String> key);
static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key);
+ // Tries to internalize given string and returns string handle on success
+ // or an empty handle otherwise.
+ MUST_USE_RESULT static MaybeHandle<String> InternalizeStringIfExists(
+ Isolate* isolate,
+ Handle<String> string);
+
// Looks up a string that is equal to the given string and returns
- // true if it is found, assigning the string to the given output
- // parameter.
- bool LookupStringIfExists(String* str, String** result);
- bool LookupTwoCharsStringIfExists(uint16_t c1, uint16_t c2, String** result);
+ // string handle if it is found, or an empty handle otherwise.
+ MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists(
+ Isolate* isolate,
+ Handle<String> str);
+ MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists(
+ Isolate* isolate,
+ uint16_t c1,
+ uint16_t c2);
// Casting.
static inline StringTable* cast(Object* obj);
InitializationFlag init_flag,
int slot_index) {
DisallowHeapAllocation no_gc;
- String* internalized_name;
+ Handle<String> internalized_name;
ASSERT(slot_index > kNotFound);
- if (name->GetIsolate()->heap()->InternalizeStringIfExists(
- *name, &internalized_name)) {
- int index = Hash(*data, internalized_name);
+ if (StringTable::InternalizeStringIfExists(name->GetIsolate(), name).
+ ToHandle(&internalized_name)) {
+ int index = Hash(*data, *internalized_name);
Key& key = keys_[index];
key.data = *data;
- key.name = internalized_name;
+ key.name = *internalized_name;
// Please note value only takes a uint as index.
values_[index] = Value(mode, init_flag, slot_index - kNotFound).raw();
#ifdef DEBUG
InitializationFlag init_flag,
int slot_index) {
DisallowHeapAllocation no_gc;
- String* internalized_name;
- if (name->GetIsolate()->heap()->InternalizeStringIfExists(
- *name, &internalized_name)) {
+ Handle<String> internalized_name;
+ if (StringTable::InternalizeStringIfExists(name->GetIsolate(), name).
+ ToHandle(&internalized_name)) {
int index = Hash(*data, *name);
Key& key = keys_[index];
ASSERT(key.data == *data);