summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-06-13 21:33:10 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-22 00:26:25 +0430
commitbaa4195daaf805fa09743a63c2c7f60cf2214289 (patch)
treec275fbff7b64a59ff1f832405ff911f6c6710a37 /Userland/Libraries/LibWeb
parent0d2aba07aaf3fa6829a140ad471b212c9ec5dc72 (diff)
downloadserenity-baa4195daaf805fa09743a63c2c7f60cf2214289.zip
LibWeb: Avoid resolving the wasm call address type on every invocation
This is a waste of time, and it's not a cheap operation.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
index 027c138919..153e0433c9 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
@@ -317,18 +317,19 @@ Optional<Wasm::Value> to_webassembly_value(JS::Value value, const Wasm::ValueTyp
JS::NativeFunction* create_native_function(Wasm::FunctionAddress address, String name, JS::GlobalObject& global_object)
{
+ Optional<Wasm::FunctionType> type;
+ WebAssemblyObject::s_abstract_machine.store().get(address)->visit([&](const auto& value) { type = value.type(); });
// FIXME: Cache these.
return JS::NativeFunction::create(
global_object,
name,
- [address](JS::VM& vm, JS::GlobalObject& global_object) -> JS::Value {
+ [address, type = type.release_value()](JS::VM& vm, JS::GlobalObject& global_object) -> JS::Value {
Vector<Wasm::Value> values;
- Optional<Wasm::FunctionType> type;
- WebAssemblyObject::s_abstract_machine.store().get(address)->visit([&](const auto& value) { type = value.type(); });
+ values.ensure_capacity(type.parameters().size());
// Grab as many values as needed and convert them.
size_t index = 0;
- for (auto& type : type.value().parameters()) {
+ for (auto& type : type.parameters()) {
auto result = to_webassembly_value(vm.argument(index++), type, global_object);
if (result.has_value())
values.append(result.release_value());