From 06ffc0c4db1619e130b57b61d6d809ae17ccb01c Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 6 Jul 2021 14:28:55 +0430 Subject: [PATCH] LibWasm: Don't create useless temporary strings for trap reasons These strings are only used when execution traps, so there's no reason to create actual strings until that happens; instead switch to using StringViews. --- .../Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp | 4 ++-- .../Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index e4511fa0e0..0c7ce0c6a2 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -17,7 +17,7 @@ namespace Wasm { #define TRAP_IF_NOT(x) \ do { \ - if (trap_if_not(x, #x)) { \ + if (trap_if_not(x, #x##sv)) { \ dbgln_if(WASM_TRACE_DEBUG, "Trapped because {} failed, at line {}", #x, __LINE__); \ return; \ } \ @@ -25,7 +25,7 @@ namespace Wasm { #define TRAP_IF_NOT_NORETURN(x) \ do { \ - if (trap_if_not(x, #x)) { \ + if (trap_if_not(x, #x##sv)) { \ dbgln_if(WASM_TRACE_DEBUG, "Trapped because {} failed, at line {}", #x, __LINE__); \ } \ } while (false) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h index 7a917ab6fc..f853f1f08d 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h @@ -49,10 +49,10 @@ protected: T read_value(ReadonlyBytes data); Vector pop_values(Configuration& configuration, size_t count); - bool trap_if_not(bool value, String reason) + bool trap_if_not(bool value, StringView reason) { if (!value) - m_trap = Trap { move(reason) }; + m_trap = Trap { reason }; return m_trap.has_value(); }