Skip to content

Commit f7b22d6

Browse files
committed
src: use local vector
1 parent 89b4ab5 commit f7b22d6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/node_json_parser.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ using v8::Null;
4444
using v8::Number;
4545
using v8::Object;
4646
using v8::Primitive;
47+
using v8::Array;
4748
using v8::String;
4849
using v8::Undefined;
4950
using v8::Value;
51+
using v8::LocalVector;
5052

5153
template <typename T>
5254
inline MaybeLocal<Value> ToV8Number(Isolate* isolate,
@@ -107,23 +109,21 @@ MaybeLocal<Value> ConvertSimdjsonElement(Isolate* isolate,
107109

108110
THROW_AND_RETURN_EMPTY_IF_SIMDJSON_ERROR(isolate, error);
109111

110-
Local<Array> v8_array =
111-
v8::Array::New(isolate, array.size());
112-
113-
Local<Context> context = isolate->GetCurrentContext();
112+
size_t size = array.size();
113+
LocalVector<Value> elements(isolate);
114+
elements.reserve(size);
114115

115-
uint32_t index = 0;
116116
for (simdjson::dom::element child : array) {
117117
Local<Value> converted;
118118

119119
if (!ConvertSimdjsonElement(isolate, child).ToLocal(&converted))
120120
return MaybeLocal<Value>();
121121

122-
if (v8_array->Set(context, index, converted).IsNothing())
123-
return MaybeLocal<Value>();
124-
index++;
122+
elements.push_back(converted);
125123
}
126124

125+
Local<Array> v8_array = Array::New(isolate, elements.data(), size);
126+
127127
return MaybeLocal<Value>(v8_array);
128128
}
129129
case simdjson::dom::element_type::OBJECT: {

0 commit comments

Comments
 (0)