From 8e04791480d00e6a681cc0dd781dcd2ef7e19853 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 4 Mar 2024 10:00:39 +0100 Subject: [PATCH] LibJS/Bytecode: Combine has_index() and get() in GetByVal and PutByVal Since get() returns an empty Optional if the index is not present, we can combine these two into a single get() operation and save the cost of a virtual call. --- .../LibJS/Bytecode/CommonImplementations.h | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h index 1396ee0c31..d5a1fcc4bc 100644 --- a/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h +++ b/Userland/Libraries/LibJS/Bytecode/CommonImplementations.h @@ -123,11 +123,13 @@ inline ThrowCompletionOr get_by_value(VM& vm, Value base_value, Value pro // For "non-typed arrays": if (!object.may_interfere_with_indexed_property_access() - && object_storage - && object_storage->has_index(index)) { - auto value = object_storage->get(index)->value; - if (!value.is_accessor()) - return value; + && object_storage) { + auto maybe_value = object_storage->get(index); + if (maybe_value.has_value()) { + auto value = maybe_value->value; + if (!value.is_accessor()) + return value; + } } // For typed arrays: @@ -398,12 +400,14 @@ inline ThrowCompletionOr put_by_value(VM& vm, Value base, Value property_k // For "non-typed arrays": if (storage && storage->is_simple_storage() - && !object.may_interfere_with_indexed_property_access() - && storage->has_index(index)) { - auto existing_value = storage->get(index)->value; - if (!existing_value.is_accessor()) { - storage->put(index, value); - return {}; + && !object.may_interfere_with_indexed_property_access()) { + auto maybe_value = storage->get(index); + if (maybe_value.has_value()) { + auto existing_value = maybe_value->value; + if (!existing_value.is_accessor()) { + storage->put(index, value); + return {}; + } } }