From c7a89027464e93fde16884a0267bc0c56ffb1122 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Tue, 8 Feb 2022 22:22:03 +0200 Subject: [PATCH] LibJS: Make TypedArray::element_name return FlyString instead of String This ensures that comparison between TypedArray names will be essentially free (just a pointer comparison), which will allow us to efficiently implement specification steps like: "24. If srcType is the same as targetType, then" efficiently. --- Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp | 4 ++-- Userland/Libraries/LibJS/Runtime/TypedArray.cpp | 2 +- Userland/Libraries/LibJS/Runtime/TypedArray.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp b/Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp index 1f75a9f125..e5fb0632a6 100644 --- a/Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp @@ -28,14 +28,14 @@ static ThrowCompletionOr validate_integer_typed_array(GlobalObject auto* buffer = typed_array.viewed_array_buffer(); // 4. Let typeName be typedArray.[[TypedArrayName]]. - auto type_name = typed_array.element_name(); + auto const& type_name = typed_array.element_name(); // 5. Let type be the Element Type value in Table 72 for typeName. // 6. If waitable is true, then if (waitable) { // a. If typeName is not "Int32Array" or "BigInt64Array", throw a TypeError exception. - if ((type_name != "Int32Array"sv) && (type_name != "BigInt64Array"sv)) + if ((type_name != vm.names.Int32Array.as_string()) && (type_name != vm.names.BigInt64Array.as_string())) return vm.throw_completion(global_object, ErrorType::TypedArrayTypeIsNot, type_name, "Int32 or BigInt64"sv); } // 7. Else, diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 1405e3ef7c..27e4ba3e7a 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -395,7 +395,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor) \ ClassName::~ClassName() { } \ \ - String ClassName::element_name() const \ + FlyString const& ClassName::element_name() const \ { \ return vm().names.ClassName.as_string(); \ } \ diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h index 631c254999..b765c57caa 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.h +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h @@ -44,7 +44,7 @@ public: void set_viewed_array_buffer(ArrayBuffer* array_buffer) { m_viewed_array_buffer = array_buffer; } virtual size_t element_size() const = 0; - virtual String element_name() const = 0; + virtual FlyString const& element_name() const = 0; // 25.1.2.6 IsUnclampedIntegerElementType ( type ), https://tc39.es/ecma262/#sec-isunclampedintegerelementtype virtual bool is_unclamped_integer_element_type() const = 0; @@ -482,7 +482,7 @@ ThrowCompletionOr typed_array_create(GlobalObject& global_objec static ThrowCompletionOr create(GlobalObject&, u32 length); \ static ClassName* create(GlobalObject&, u32 length, ArrayBuffer& buffer); \ ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer); \ - virtual String element_name() const override; \ + virtual FlyString const& element_name() const override; \ }; \ class PrototypeName final : public Object { \ JS_OBJECT(PrototypeName, Object); \