Skip to content

Commit

Permalink
src: use string view instead of local
Browse files Browse the repository at this point in the history
This reverts commit 1340a81744b5a934b4ea0423bc01d424fa152127.

src: use direct initialzation and const string view signature
  • Loading branch information
JonasBa committed Sep 19, 2024
1 parent 5b4d2e1 commit 4ded9ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include "path.h"
#include "sqlite3.h"
#include "util-inl.h"
#include "util.h"

#include <cinttypes>
#include <string_view>

namespace node {
namespace sqlite {
Expand Down Expand Up @@ -91,12 +93,11 @@ inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, const char* message) {

DatabaseSync::DatabaseSync(Environment* env,
Local<Object> object,
Local<String> location,
const std::string_view location,
bool open)
: BaseObject(env, object) {
MakeWeak();
Utf8Value utf8_location(env->isolate(), location);
location_ = utf8_location.ToString();
location_ = std::string(location);
connection_ = nullptr;

if (open) {
Expand Down Expand Up @@ -191,7 +192,10 @@ void DatabaseSync::New(const FunctionCallbackInfo<Value>& args) {
}
}

new DatabaseSync(env, args.This(), args[0].As<String>(), open);
BufferValue location(env->isolate(), args[0]);
CHECK_NOT_NULL(*location);
ToNamespacedPath(env, &location);
new DatabaseSync(env, args.This(), location.ToStringView(), open);
}

void DatabaseSync::Open(const FunctionCallbackInfo<Value>& args) {
Expand Down Expand Up @@ -388,7 +392,7 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
double val = value.As<Number>()->Value();
r = sqlite3_bind_double(statement_, index, val);
} else if (value->IsString()) {
auto val = Utf8Value(env()->isolate(), value.As<String>());
Utf8Value val(env()->isolate(), value.As<String>());
r = sqlite3_bind_text(
statement_, index, *val, val.length(), SQLITE_TRANSIENT);
} else if (value->IsNull()) {
Expand Down
3 changes: 2 additions & 1 deletion src/node_sqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "util.h"

#include <map>
#include <string_view>
#include <unordered_set>

namespace node {
Expand All @@ -20,7 +21,7 @@ class DatabaseSync : public BaseObject {
public:
DatabaseSync(Environment* env,
v8::Local<v8::Object> object,
v8::Local<v8::String> location,
std::string_view location,
bool open);
void MemoryInfo(MemoryTracker* tracker) const override;
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down

0 comments on commit 4ded9ab

Please sign in to comment.