From f37fbcf516ccb26e56c14ebdd0c248e8416580e9 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 9 Mar 2022 15:34:06 -0500 Subject: [PATCH] LibJS: Preallocate the list returned from CreateListFromArrayLike This list has up to 10,000 elements in some test262 tests, so let's avoid frequent allocation bumps. --- Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index f275d58c84..09f3d241ac 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -115,6 +115,7 @@ ThrowCompletionOr> create_list_from_array_like(GlobalObject& // 4. Let list be a new empty List. auto list = MarkedVector { heap }; + list.ensure_capacity(length); // 5. Let index be 0. // 6. Repeat, while index < len, @@ -130,7 +131,7 @@ ThrowCompletionOr> create_list_from_array_like(GlobalObject& TRY(check_value(next)); // d. Append next as the last element of list. - list.append(next); + list.unchecked_append(next); } // 7. Return list.