From 34906bfbc99d31b3e62d2d006af2247d8418ba2f Mon Sep 17 00:00:00 2001 From: Petr Makhnev <51853996+i582@users.noreply.github.com> Date: Fri, 11 Oct 2024 03:15:28 +0400 Subject: Optimize Module::get_* family of functions with std::string_view in getModuleElement (#6998) Passing a constant string to functions requires memory allocation, and allocation is inherently slow. Since we are using C++17, we can use string_view and remove this unnecessary allocation. Although the code seems simple enough for the optimizer to remove this allocation after inlining, tests on Clang 18 show that this is not the case (on Apple Silicon at least). --- src/wasm/wasm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/wasm/wasm.cpp') diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index e8de4572b..0245fc01e 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -1523,7 +1523,7 @@ void Function::clearDebugInfo() { template typename Map::mapped_type& -getModuleElement(Map& m, Name name, const std::string& funcName) { +getModuleElement(Map& m, Name name, std::string_view funcName) { auto iter = m.find(name); if (iter == m.end()) { Fatal() << "Module::" << funcName << ": " << name << " does not exist"; -- cgit v1.2.3