From 22969a8e929eae00a45989acae99eb5a97269358 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 25 Jul 2024 19:16:40 +1200 Subject: [PATCH] Bindings: Avoid second property index lookup for platform objects While conceptually is_supported_property_index is a cheap index lookup, it is not currently cheap for an container such as HTMLAllCollection that is operating on an uncached collection. Instead - just do the lookup once. It also happens to look a little nicer to not blindly dereference an optional. --- Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp b/Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp index b8ed343bea9..61bf2b21bbe 100644 --- a/Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/PlatformObject.cpp @@ -91,12 +91,12 @@ JS::ThrowCompletionOr> PlatformObject::legacy_p u32 index = property_name.as_number(); // 2. If index is a supported property index, then: - if (is_supported_property_index(index)) { + if (auto maybe_value = item_value(index); maybe_value.has_value()) { // 1. Let operation be the operation used to declare the indexed property getter. // 2. Let value be an uninitialized variable. // 3. If operation was defined without an identifier, then set value to the result of performing the steps listed in the interface description to determine the value of an indexed property with index as the index. // 4. Otherwise, operation was defined with an identifier. Set value to the result of performing the method steps of operation with O as this and « index » as the argument values. - auto value = *item_value(index); + auto value = maybe_value.release_value(); // 5. Let desc be a newly created Property Descriptor with no fields. JS::PropertyDescriptor descriptor;