Commit 7a0ae73b authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[ast] Add a Flatten method for AstConsString

This allows off-thread flattening.

Bug: chromium:1011762
Change-Id: If83f7bbcbf74165987a4c157184f5b92dc554971
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1924437
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65075}
parent d1462a56
......@@ -246,6 +246,50 @@ AstConsString* AstValueFactory::NewConsString(const AstRawString* str1,
return NewConsString()->AddString(zone_, str1)->AddString(zone_, str2);
}
const AstRawString* AstValueFactory::Flatten(const AstConsString* str) {
if (str->IsEmpty()) return empty_string();
AstConsString::Segment segment = str->segment_;
if (!segment.next) return segment.string;
int length = segment.string->length();
bool is_one_byte = segment.string->is_one_byte();
while (segment.next) {
segment = *segment.next;
length += segment.string->length();
is_one_byte &= segment.string->is_one_byte();
}
if (is_one_byte) {
Vector<byte> data(zone()->NewArray<byte>(length), length);
segment = str->segment_;
byte* p = data.begin();
while (true) {
CopyChars(p, segment.string->raw_data(), segment.string->length());
p += segment.string->length();
if (!segment.next) break;
segment = *segment.next;
}
return GetOneByteString(data);
}
Vector<uint16_t> data(zone()->NewArray<uint16_t>(length), length);
segment = str->segment_;
uint16_t* p = data.begin();
while (true) {
if (segment.string->is_one_byte()) {
CopyChars(p, segment.string->raw_data(), segment.string->length());
} else {
CopyChars(p,
reinterpret_cast<const uint16_t*>(segment.string->raw_data()),
segment.string->length());
}
p += segment.string->length();
if (!segment.next) break;
segment = *segment.next;
}
return GetTwoByteString(data);
}
void AstValueFactory::Internalize(Isolate* isolate) {
// Strings need to be internalized before values, because values refer to
// strings.
......
......@@ -312,6 +312,7 @@ class AstValueFactory {
V8_EXPORT_PRIVATE AstConsString* NewConsString(const AstRawString* str);
V8_EXPORT_PRIVATE AstConsString* NewConsString(const AstRawString* str1,
const AstRawString* str2);
V8_EXPORT_PRIVATE const AstRawString* Flatten(const AstConsString* str);
V8_EXPORT_PRIVATE void Internalize(Isolate* 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