Skip to content

Commit 4ded9ab

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 5b4d2e1 commit 4ded9ab

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

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 {
@@ -91,12 +93,11 @@ inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, const char* message) {
9193

9294
DatabaseSync::DatabaseSync(Environment* env,
9395
Local<Object> object,
94-
Local<String> location,
96+
const std::string_view location,
9597
bool open)
9698
: BaseObject(env, object) {
9799
MakeWeak();
98-
Utf8Value utf8_location(env->isolate(), location);
99-
location_ = utf8_location.ToString();
100+
location_ = std::string(location);
100101
connection_ = nullptr;
101102

102103
if (open) {
@@ -191,7 +192,10 @@ void DatabaseSync::New(const FunctionCallbackInfo<Value>& args) {
191192
}
192193
}
193194

194-
new DatabaseSync(env, args.This(), args[0].As<String>(), open);
195+
BufferValue location(env->isolate(), args[0]);
196+
CHECK_NOT_NULL(*location);
197+
ToNamespacedPath(env, &location);
198+
new DatabaseSync(env, args.This(), location.ToStringView(), open);
195199
}
196200

197201
void DatabaseSync::Open(const FunctionCallbackInfo<Value>& args) {
@@ -388,7 +392,7 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {
388392
double val = value.As<Number>()->Value();
389393
r = sqlite3_bind_double(statement_, index, val);
390394
} else if (value->IsString()) {
391-
auto val = Utf8Value(env()->isolate(), value.As<String>());
395+
Utf8Value val(env()->isolate(), value.As<String>());
392396
r = sqlite3_bind_text(
393397
statement_, index, *val, val.length(), SQLITE_TRANSIENT);
394398
} 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)