Skip to content

Commit 9a1e5b8

Browse files
committed
fix: Avoid shared_ptr allocation for vector
1 parent 20b4999 commit 9a1e5b8

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

package/cpp/sqliteExecuteBatch.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ std::vector<BatchQuery> batchParamsToCommands(const std::vector<BatchQueryComman
1919
if (std::holds_alternative<NestedParamsVec>(*command.params)) {
2020
// This arguments is an array of arrays, like a batch update of a single sql command.
2121
for (const auto& params : std::get<NestedParamsVec>(*command.params)) {
22-
commands.push_back(BatchQuery{command.query, std::make_shared<ParamsVec>(params)});
22+
commands.push_back(BatchQuery{command.query, ParamsVec(params)});
2323
}
2424
} else {
25-
commands.push_back(BatchQuery{command.query, std::make_shared<ParamsVec>(std::move(std::get<ParamsVec>(*command.params)))});
25+
commands.push_back(BatchQuery{command.query, std::move(std::get<ParamsVec>(*command.params))});
2626
}
2727
} else {
2828
commands.push_back(BatchQuery{command.query, NULL});
@@ -48,7 +48,7 @@ SQLiteOperationResult sqliteExecuteBatch(const std::string& dbName, const std::v
4848
auto results = SQLiteQueryResults();
4949
auto metadata = std::optional<SQLiteQueryTableMetadata>(std::nullopt);
5050
try {
51-
auto result = sqliteExecute(dbName, command.sql, *command.params.get());
51+
auto result = sqliteExecute(dbName, command.sql, command.params);
5252
rowsAffected += result.rowsAffected;
5353
} catch (NitroSQLiteException& e) {
5454
sqliteExecuteLiteral(dbName, "ROLLBACK");

package/cpp/sqliteExecuteBatch.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace margelo::rnnitrosqlite {
1313

1414
struct BatchQuery {
1515
std::string sql;
16-
std::shared_ptr<SQLiteQueryParams> params;
16+
std::optional<SQLiteQueryParams> params;
1717
};
1818

1919
/**

package/cpp/types.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ struct SQLiteExecuteQueryResult {
2727
int rowsAffected;
2828
double insertId;
2929

30-
std::unique_ptr<SQLiteQueryResults> results;
31-
std::unique_ptr<std::optional<SQLiteQueryTableMetadata>> metadata;
30+
SQLiteQueryResults results;
31+
std::optional<SQLiteQueryTableMetadata> metadata;
3232
};
3333

3434
// constexpr function that maps SQLiteColumnType to string literals

0 commit comments

Comments
 (0)