Commit ecad9dc2 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[string] Add missing two-to-one byte conversion

Use the "convert" parameter to SequentialStringKey to construct one-byte
strings out of two-byte input vectors, where appropriate.

Change-Id: I8a214b3960c677614d6f82ed3b29405e2e493e81
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2557981
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81062}
parent 3975045c
......@@ -645,6 +645,19 @@ Handle<SeqTwoByteString> FactoryBase<Impl>::NewTwoByteInternalizedString(
return result;
}
template <typename Impl>
Handle<SeqOneByteString>
FactoryBase<Impl>::NewOneByteInternalizedStringFromTwoByte(
const base::Vector<const base::uc16>& str, uint32_t raw_hash_field) {
Handle<SeqOneByteString> result =
AllocateRawOneByteInternalizedString(str.length(), raw_hash_field);
DisallowGarbageCollection no_gc;
CopyChars(
result->GetChars(no_gc, SharedStringAccessGuardIfNeeded::NotNeeded()),
str.begin(), str.length());
return result;
}
template <typename Impl>
template <typename SeqStringT>
MaybeHandle<SeqStringT> FactoryBase<Impl>::NewRawStringWithMap(
......
......@@ -213,6 +213,8 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase
const base::Vector<const uint8_t>& str, uint32_t raw_hash_field);
Handle<SeqTwoByteString> NewTwoByteInternalizedString(
const base::Vector<const base::uc16>& str, uint32_t raw_hash_field);
Handle<SeqOneByteString> NewOneByteInternalizedStringFromTwoByte(
const base::Vector<const base::uc16>& str, uint32_t raw_hash_field);
Handle<SeqOneByteString> AllocateRawOneByteInternalizedString(
int length, uint32_t raw_hash_field);
......
......@@ -359,6 +359,10 @@ class SequentialStringKey final : public StringTableKey {
if (sizeof(Char) == 1) {
internalized_string_ = isolate->factory()->NewOneByteInternalizedString(
base::Vector<const uint8_t>::cast(chars_), raw_hash_field());
} else if (convert_) {
internalized_string_ =
isolate->factory()->NewOneByteInternalizedStringFromTwoByte(
base::Vector<const uint16_t>::cast(chars_), raw_hash_field());
} else {
internalized_string_ = isolate->factory()->NewTwoByteInternalizedString(
base::Vector<const uint16_t>::cast(chars_), raw_hash_field());
......
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