Skip to content

Commit

Permalink
LibJS: Make TypedArray::element_name return FlyString instead of String
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
IdanHo authored and linusg committed Feb 8, 2022
1 parent 9839e2e commit c7a8902
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Userland/Libraries/LibJS/Runtime/AtomicsObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ static ThrowCompletionOr<ArrayBuffer*> 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<TypeError>(global_object, ErrorType::TypedArrayTypeIsNot, type_name, "Int32 or BigInt64"sv);
}
// 7. Else,
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibJS/Runtime/TypedArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); \
} \
Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibJS/Runtime/TypedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TypedArrayBase : public Object {
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;
Expand Down Expand Up @@ -482,7 +482,7 @@ ThrowCompletionOr<TypedArrayBase*> typed_array_create(GlobalObject& global_objec
static ThrowCompletionOr<ClassName*> 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); \
Expand Down

0 comments on commit c7a8902

Please sign in to comment.