Commit 494388da authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[objects] Remove unnecessary loop in LookupKey

Change-Id: Iee3a65c6df143a41b45b610a10a19ec28ad5c268
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2565513Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71518}
parent 277f4dc2
...@@ -464,57 +464,53 @@ Handle<String> StringTable::LookupKey(LocalIsolate* isolate, ...@@ -464,57 +464,53 @@ Handle<String> StringTable::LookupKey(LocalIsolate* isolate,
// allocation if another write also did an allocation. This assumes that // allocation if another write also did an allocation. This assumes that
// writes are rarer than reads. // writes are rarer than reads.
Handle<String> new_string; // Load the current string table data, in case another thread updates the
while (true) { // data while we're reading.
// Load the current string table data, in case another thread updates the const Data* data = data_.load(std::memory_order_acquire);
// data while we're reading.
const Data* data = data_.load(std::memory_order_acquire); // First try to find the string in the table. This is safe to do even if the
// table is now reallocated; we won't find a stale entry in the old table
// First try to find the string in the table. This is safe to do even if the // because the new table won't delete it's corresponding entry until the
// table is now reallocated; we won't find a stale entry in the old table // string is dead, in which case it will die in this table too and worst
// because the new table won't delete it's corresponding entry until the // case we'll have a false miss.
// string is dead, in which case it will die in this table too and worst InternalIndex entry = data->FindEntry(isolate, key, key->hash());
// case we'll have a false miss. if (entry.is_found()) {
InternalIndex entry = data->FindEntry(isolate, key, key->hash()); return handle(String::cast(data->Get(isolate, entry)), isolate);
if (entry.is_found()) { }
return handle(String::cast(data->Get(isolate, entry)), isolate);
}
// No entry found, so adding new string. // No entry found, so adding new string.
// Allocate the string before the first insertion attempt, reuse this // Allocate the string before the first insertion attempt, reuse this
// allocated value on insertion retries. If another thread concurrently // allocated value on insertion retries. If another thread concurrently
// allocates the same string, the insert will fail, the lookup above will // allocates the same string, the insert will fail, the lookup above will
// succeed, and this string will be discarded. // succeed, and this string will be discarded.
if (new_string.is_null()) new_string = key->AsHandle(isolate); Handle<String> new_string = key->AsHandle(isolate);
{ {
base::MutexGuard table_write_guard(&write_mutex_); base::MutexGuard table_write_guard(&write_mutex_);
Data* data = EnsureCapacity(isolate, 1); Data* data = EnsureCapacity(isolate, 1);
// Check one last time if the key is present in the table, in case it was // Check one last time if the key is present in the table, in case it was
// added after the check. // added after the check.
InternalIndex entry = entry = data->FindEntryOrInsertionEntry(isolate, key, key->hash());
data->FindEntryOrInsertionEntry(isolate, key, key->hash());
Object element = data->Get(isolate, entry);
Object element = data->Get(isolate, entry); if (element == empty_element()) {
if (element == empty_element()) { // This entry is empty, so write it and register that we added an
// This entry is empty, so write it and register that we added an // element.
// element. data->Set(entry, *new_string);
data->Set(entry, *new_string); data->ElementAdded();
data->ElementAdded(); return new_string;
return new_string; } else if (element == deleted_element()) {
} else if (element == deleted_element()) { // This entry was deleted, so overwrite it and register that we
// This entry was deleted, so overwrite it and register that we // overwrote a deleted element.
// overwrote a deleted element. data->Set(entry, *new_string);
data->Set(entry, *new_string); data->DeletedElementOverwritten();
data->DeletedElementOverwritten(); return new_string;
return new_string; } else {
} else { // Return the existing string as a handle.
// Return the existing string as a handle. return handle(String::cast(element), isolate);
return handle(String::cast(element), isolate);
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment