Skip to content
Prev Previous commit
Next Next commit
use localvector and then create array
  • Loading branch information
gurgunday committed Apr 4, 2025
commit de48b9391e39bd2cbfbb59f1a1f005bb7befd154
6 changes: 4 additions & 2 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1571,12 +1571,14 @@ void StatementSync::All(const FunctionCallbackInfo<Value>& args) {

while ((r = sqlite3_step(stmt->statement_)) == SQLITE_ROW) {
if (stmt->return_arrays_) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth doing this check outside of the while loop. It would mean duplicating the while loop, but then we'd only be paying the price here once per call instead of once per loop iteration.

Local<Array> row = Array::New(isolate, num_cols);
LocalVector<Value> row_values(isolate);
row_values.reserve(num_cols);
for (int i = 0; i < num_cols; ++i) {
Local<Value> val;
if (!stmt->ColumnToValue(i).ToLocal(&val)) return;
if (row->Set(env->context(), i, val).IsNothing()) return;
row_values.emplace_back(val);
}
Local<Array> row = Array::New(isolate, row_values.data(), row_values.size());
rows.emplace_back(row);
} else {
if (row_keys.size() == 0) {
Expand Down