From 425c168dedf0138cb5d5a96c1d5cccce80afe030 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 6 Jan 2023 11:00:24 -0500 Subject: AK+LibJS+LibRegex: Define an alias for UTF-16 string data storage Instead of writing out "Vector" everywhere, let's have a name for it. --- Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp | 2 +- Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp | 2 +- Userland/Libraries/LibJS/Runtime/StringConstructor.cpp | 4 ++-- Userland/Libraries/LibJS/Runtime/StringPrototype.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Utf16String.cpp | 15 +++++++-------- Userland/Libraries/LibJS/Runtime/Utf16String.h | 15 ++++++++------- 6 files changed, 20 insertions(+), 20 deletions(-) (limited to 'Userland/Libraries/LibJS') diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index 4db6c8529b..ddf89aee18 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -1233,7 +1233,7 @@ ThrowCompletionOr get_substitution(VM& vm, Utf16View const& ma auto replace_string = TRY(replacement_template.to_utf16_string(vm)); auto replace_view = replace_string.view(); - Vector result; + Utf16Data result; for (size_t i = 0; i < replace_view.length_in_code_units(); ++i) { u16 curr = replace_view.code_unit_at(i); diff --git a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp index cecc841b6e..c29c4b0cc8 100644 --- a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp +++ b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp @@ -180,7 +180,7 @@ void PrimitiveString::resolve_rope_if_needed() const auto const& lhs_string = m_lhs->utf16_string(); auto const& rhs_string = m_rhs->utf16_string(); - Vector combined; + Utf16Data combined; combined.ensure_capacity(lhs_string.length_in_code_units() + rhs_string.length_in_code_units()); combined.extend(lhs_string.string()); combined.extend(rhs_string.string()); diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp index 9fd6b22f3c..ca6e5130ea 100644 --- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -100,7 +100,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw) // 22.1.2.1 String.fromCharCode ( ...codeUnits ), https://tc39.es/ecma262/#sec-string.fromcharcode JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code) { - Vector string; + Utf16Data string; string.ensure_capacity(vm.argument_count()); for (size_t i = 0; i < vm.argument_count(); ++i) @@ -112,7 +112,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code) // 22.1.2.2 String.fromCodePoint ( ...codePoints ), https://tc39.es/ecma262/#sec-string.fromcodepoint JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_code_point) { - Vector string; + Utf16Data string; string.ensure_capacity(vm.argument_count()); // This will be an under-estimate if any code point is > 0xffff. for (size_t i = 0; i < vm.argument_count(); ++i) { diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index 9f2ccd6a2c..c43706bbb7 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -518,7 +518,7 @@ static ThrowCompletionOr pad_string(VM& vm, Utf16String string, PadPlacem if (max_length <= string_length) return PrimitiveString::create(vm, move(string)); - Utf16String fill_string(Vector { 0x20 }); + Utf16String fill_string(Utf16Data { 0x20 }); if (!vm.argument(1).is_undefined()) { fill_string = TRY(vm.argument(1).to_utf16_string(vm)); if (fill_string.is_empty()) diff --git a/Userland/Libraries/LibJS/Runtime/Utf16String.cpp b/Userland/Libraries/LibJS/Runtime/Utf16String.cpp index b9aacbaa5e..821dc88db4 100644 --- a/Userland/Libraries/LibJS/Runtime/Utf16String.cpp +++ b/Userland/Libraries/LibJS/Runtime/Utf16String.cpp @@ -1,11 +1,10 @@ /* - * Copyright (c) 2021, Tim Flynn + * Copyright (c) 2021-2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #include -#include #include namespace JS { @@ -17,7 +16,7 @@ static NonnullRefPtr the_empty_utf16_string() return empty_string; } -Utf16StringImpl::Utf16StringImpl(Vector string) +Utf16StringImpl::Utf16StringImpl(Utf16Data string) : m_string(move(string)) { } @@ -27,7 +26,7 @@ NonnullRefPtr Utf16StringImpl::create() return adopt_ref(*new Utf16StringImpl()); } -NonnullRefPtr Utf16StringImpl::create(Vector string) +NonnullRefPtr Utf16StringImpl::create(Utf16Data string) { return adopt_ref(*new Utf16StringImpl(move(string))); } @@ -39,13 +38,13 @@ NonnullRefPtr Utf16StringImpl::create(StringView string) NonnullRefPtr Utf16StringImpl::create(Utf16View const& view) { - Vector string; + Utf16Data string; string.ensure_capacity(view.length_in_code_units()); string.append(view.data(), view.length_in_code_units()); return create(move(string)); } -Vector const& Utf16StringImpl::string() const +Utf16Data const& Utf16StringImpl::string() const { return m_string; } @@ -62,7 +61,7 @@ Utf16String::Utf16String() { } -Utf16String::Utf16String(Vector string) +Utf16String::Utf16String(Utf16Data string) : m_string(Detail::Utf16StringImpl::create(move(string))) { } @@ -77,7 +76,7 @@ Utf16String::Utf16String(Utf16View const& string) { } -Vector const& Utf16String::string() const +Utf16Data const& Utf16String::string() const { return m_string->string(); } diff --git a/Userland/Libraries/LibJS/Runtime/Utf16String.h b/Userland/Libraries/LibJS/Runtime/Utf16String.h index 32ffa733c8..fdcc014252 100644 --- a/Userland/Libraries/LibJS/Runtime/Utf16String.h +++ b/Userland/Libraries/LibJS/Runtime/Utf16String.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Tim Flynn + * Copyright (c) 2021-2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace JS { @@ -20,18 +21,18 @@ public: ~Utf16StringImpl() = default; static NonnullRefPtr create(); - static NonnullRefPtr create(Vector); + static NonnullRefPtr create(Utf16Data); static NonnullRefPtr create(StringView); static NonnullRefPtr create(Utf16View const&); - Vector const& string() const; + Utf16Data const& string() const; Utf16View view() const; private: Utf16StringImpl() = default; - explicit Utf16StringImpl(Vector string); + explicit Utf16StringImpl(Utf16Data string); - Vector m_string; + Utf16Data m_string; }; } @@ -39,11 +40,11 @@ private: class Utf16String { public: Utf16String(); - explicit Utf16String(Vector); + explicit Utf16String(Utf16Data); explicit Utf16String(StringView); explicit Utf16String(Utf16View const&); - Vector const& string() const; + Utf16Data const& string() const; Utf16View view() const; Utf16View substring_view(size_t code_unit_offset, size_t code_unit_length) const; Utf16View substring_view(size_t code_unit_offset) const; -- cgit v1.2.3