Commit 74dbb804 authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[runtime] Enable turning ConsStrings into ThinStrings

We previously missed out on turning ConsString objects into ThinStrings
due to the flattening step in StringTable::LookupString.

  // Example input string:
  string = cons("A", cons"B", "C"))
  // After flatten:
  string == cons("ABC", "")
  // OLD: After internalising and thinning:
  string == cons(#"ABC", "")

The new behaviour yields a thin string after internalising:

  // NEW: After internalising and thinning:
  string == thin(#"ABC")

Change-Id: I99bbebd52fa02ecfeb2289cb85b69f3e01175cdd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3667080
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81004}
parent 592c8365
......@@ -484,27 +484,24 @@ Handle<String> StringTable::LookupString(Isolate* isolate,
//
// For lookup hits, we use the StringForwardingTable for shared strings to
// delay the transition into a ThinString to the next stop-the-world GC.
string = String::Flatten(isolate, string);
if (string->IsInternalizedString()) return string;
string->EnsureHash();
uint32_t raw_hash_field = string->raw_hash_field(kAcquireLoad);
if (String::IsForwardingIndex(raw_hash_field)) {
const int index = String::HashBits::decode(raw_hash_field);
return handle(
isolate->string_forwarding_table()->GetForwardString(isolate, index),
isolate);
Handle<String> result = String::Flatten(isolate, string);
if (!result->IsInternalizedString()) {
result->EnsureHash();
uint32_t raw_hash_field = result->raw_hash_field(kAcquireLoad);
if (String::IsForwardingIndex(raw_hash_field)) {
const int index = String::HashBits::decode(raw_hash_field);
result = handle(
isolate->string_forwarding_table()->GetForwardString(isolate, index),
isolate);
} else {
InternalizedStringKey key(result, raw_hash_field);
result = LookupKey(isolate, &key);
}
}
InternalizedStringKey key(string, raw_hash_field);
Handle<String> result = LookupKey(isolate, &key);
if (!string->IsInternalizedString()) {
if (*string != *result && !string->IsThinString()) {
SetInternalizedReference(isolate, *string, *result);
}
return result;
}
......
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