Skip to content

Commit fe5c872

Browse files
committed
src: use string view instead of local
This reverts commit 1340a81744b5a934b4ea0423bc01d424fa152127. src: use direct initialzation and const string view signature
1 parent 25271b2 commit fe5c872

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/node_sqlite.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#include "path.h"
1010
#include "sqlite3.h"
1111
#include "util-inl.h"
12+
#include "util.h"
1213

1314
#include <cinttypes>
15+
#include <string_view>
1416

1517
namespace node {
1618
namespace sqlite {
@@ -78,12 +80,11 @@ inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, sqlite3* db) {
7880

7981
DatabaseSync::DatabaseSync(Environment* env,
8082
Local<Object> object,
81-
Local<String> location,
83+
const std::string_view location,
8284
bool open)
8385
: BaseObject(env, object) {
8486
MakeWeak();
85-
Utf8Value utf8_location(env->isolate(), location);
86-
location_ = utf8_location.ToString();
87+
location_ = std::string(location);
8788
connection_ = nullptr;
8889

8990
if (open) {
@@ -178,7 +179,10 @@ void DatabaseSync::New(const FunctionCallbackInfo<Value>& args) {
178179
}
179180
}
180181

181-
new DatabaseSync(env, args.This(), args[0].As<String>(), open);
182+
BufferValue location(env->isolate(), args[0]);
183+
CHECK_NOT_NULL(*location);
184+
ToNamespacedPath(env, &location);
185+
new DatabaseSync(env, args.This(), location.ToStringView(), open);
182186
}
183187

184188
void DatabaseSync::Open(const FunctionCallbackInfo<Value>& args) {
@@ -375,7 +379,7 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
375379
double val = value.As<Number>()->Value();
376380
r = sqlite3_bind_double(statement_, index, val);
377381
} else if (value->IsString()) {
378-
auto val = Utf8Value(env()->isolate(), value.As<String>());
382+
Utf8Value val(env()->isolate(), value.As<String>());
379383
r = sqlite3_bind_text(
380384
statement_, index, *val, val.length(), SQLITE_TRANSIENT);
381385
} else if (value->IsNull()) {

src/node_sqlite.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "util.h"
1010

1111
#include <map>
12+
#include <string_view>
1213
#include <unordered_set>
1314

1415
namespace node {
@@ -20,7 +21,7 @@ class DatabaseSync : public BaseObject {
2021
public:
2122
DatabaseSync(Environment* env,
2223
v8::Local<v8::Object> object,
23-
v8::Local<v8::String> location,
24+
std::string_view location,
2425
bool open);
2526
void MemoryInfo(MemoryTracker* tracker) const override;
2627
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);

0 commit comments

Comments
 (0)