Skip to content

Commit fd2a144

Browse files
committed
repair
1 parent 7164b3d commit fd2a144

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/node_sqlite.cc

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ static constexpr std::array<LimitInfo, 11> kLimitMapping = {{
201201
{"triggerDepth", SQLITE_LIMIT_TRIGGER_DEPTH, SQLITE_MAX_TRIGGER_DEPTH},
202202
}};
203203

204-
// Helper function to find limit index from JS property name
205-
static constexpr int GetLimitIndexFromName(std::string_view name) {
206-
for (size_t i = 0; i < kLimitMapping.size(); ++i) {
207-
if (name == kLimitMapping[i].js_name) {
208-
return static_cast<int>(i);
204+
// Helper function to find limit info from JS property name
205+
static constexpr const LimitInfo* GetLimitInfoFromName(std::string_view name) {
206+
for (const auto& info : kLimitMapping) {
207+
if (name == info.js_name) {
208+
return &info;
209209
}
210210
}
211-
return -1; // Not found
211+
return nullptr;
212212
}
213213

214214
inline MaybeLocal<Object> CreateSQLiteError(Isolate* isolate,
@@ -792,9 +792,9 @@ Intercepted DatabaseSyncLimits::LimitsGetter(
792792
Isolate* isolate = env->isolate();
793793

794794
Utf8Value prop_name(isolate, property);
795-
int idx = GetLimitIndexFromName(prop_name.ToStringView());
795+
const LimitInfo* limit_info = GetLimitInfoFromName(prop_name.ToStringView());
796796

797-
if (idx < 0) {
797+
if (!limit_info) {
798798
return Intercepted::kNo; // Unknown property, let default handling occur
799799
}
800800

@@ -804,7 +804,7 @@ Intercepted DatabaseSyncLimits::LimitsGetter(
804804
}
805805

806806
int current_value = sqlite3_limit(
807-
limits->database_->Connection(), kLimitMapping[idx].sqlite_limit_id, -1);
807+
limits->database_->Connection(), limit_info->sqlite_limit_id, -1);
808808
info.GetReturnValue().Set(Integer::New(isolate, current_value));
809809
return Intercepted::kYes;
810810
}
@@ -824,9 +824,9 @@ Intercepted DatabaseSyncLimits::LimitsSetter(
824824
Isolate* isolate = env->isolate();
825825

826826
Utf8Value prop_name(isolate, property);
827-
int idx = GetLimitIndexFromName(*prop_name);
827+
const LimitInfo* limit_info = GetLimitInfoFromName(*prop_name);
828828

829-
if (idx < 0) {
829+
if (!limit_info) {
830830
return Intercepted::kNo;
831831
}
832832

@@ -849,15 +849,14 @@ Intercepted DatabaseSyncLimits::LimitsSetter(
849849
}
850850

851851
// Validate against compile-time maximum
852-
if (new_value > kLimitMapping[idx].max_value) {
852+
if (new_value > limit_info->max_value) {
853853
THROW_ERR_OUT_OF_RANGE(isolate,
854854
"Limit value exceeds compile-time maximum.");
855855
return Intercepted::kYes;
856856
}
857857

858-
sqlite3_limit(limits->database_->Connection(),
859-
kLimitMapping[idx].sqlite_limit_id,
860-
new_value);
858+
sqlite3_limit(
859+
limits->database_->Connection(), limit_info->sqlite_limit_id, new_value);
861860
return Intercepted::kYes;
862861
}
863862

@@ -869,9 +868,9 @@ Intercepted DatabaseSyncLimits::LimitsQuery(
869868

870869
Isolate* isolate = info.GetIsolate();
871870
Utf8Value prop_name(isolate, property);
872-
int idx = GetLimitIndexFromName(prop_name.ToStringView());
871+
const LimitInfo* limit_info = GetLimitInfoFromName(prop_name.ToStringView());
873872

874-
if (idx < 0) {
873+
if (!limit_info) {
875874
return Intercepted::kNo;
876875
}
877876

0 commit comments

Comments
 (0)