From 98348d9a33bafe1a934600c7da2c5ff8133c77d5 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 30 Jan 2022 16:52:40 -0500 Subject: [PATCH] LibJS: Allow calling Array::create_from without allocating a Vector This method works as-is with a Span instead of a Vector (with some minor const correctness adjustments). --- Userland/Libraries/LibJS/Runtime/Array.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Array.h b/Userland/Libraries/LibJS/Runtime/Array.h index d06d607079..b16f809e0d 100644 --- a/Userland/Libraries/LibJS/Runtime/Array.h +++ b/Userland/Libraries/LibJS/Runtime/Array.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -23,12 +24,12 @@ public: static Array* create_from(GlobalObject&, Vector const&); // Non-standard but equivalent to CreateArrayFromList. template - static Array* create_from(GlobalObject& global_object, Vector& elements, Function map_fn) + static Array* create_from(GlobalObject& global_object, Span elements, Function map_fn) { auto& vm = global_object.vm(); auto values = MarkedValueList { global_object.heap() }; values.ensure_capacity(elements.size()); - for (auto& element : elements) { + for (auto const& element : elements) { values.append(map_fn(element)); VERIFY(!vm.exception()); }