瀏覽代碼

LibJS: Pre-size a HashTable in function_declaration_instantiation()

The dynamic resizing of this hash table was showing up in profiles.
Since we have an idea of how big it will get, use ensure_capacity().
Andreas Kling 3 年之前
父節點
當前提交
b00b461b31
共有 1 個文件被更改,包括 2 次插入0 次删除
  1. 2 0
      Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp

+ 2 - 0
Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp

@@ -287,6 +287,8 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
     Environment* var_environment;
 
     HashTable<FlyString> instantiated_var_names;
+    if (scope_body)
+        instantiated_var_names.ensure_capacity(scope_body->var_declaration_count());
 
     if (!has_parameter_expressions) {
         if (scope_body) {