Skip to content

Commit 7164b3d

Browse files
committed
used single cycle
1 parent 346d53c commit 7164b3d

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

src/node_sqlite.cc

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,11 @@ 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 ID from JS property name
205-
static constexpr int GetLimitIdFromName(std::string_view name) {
206-
for (const auto& info : kLimitMapping) {
207-
if (name == info.js_name) {
208-
return info.sqlite_limit_id;
209-
}
210-
}
211-
return -1; // Not found
212-
}
213-
214-
// Helper function to get max value for a limit ID
215-
static constexpr int GetMaxValueForLimitId(int limit_id) {
216-
for (const auto& info : kLimitMapping) {
217-
if (info.sqlite_limit_id == limit_id) {
218-
return info.max_value;
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);
219209
}
220210
}
221211
return -1; // Not found
@@ -802,9 +792,9 @@ Intercepted DatabaseSyncLimits::LimitsGetter(
802792
Isolate* isolate = env->isolate();
803793

804794
Utf8Value prop_name(isolate, property);
805-
int limit_id = GetLimitIdFromName(prop_name.ToStringView());
795+
int idx = GetLimitIndexFromName(prop_name.ToStringView());
806796

807-
if (limit_id < 0) {
797+
if (idx < 0) {
808798
return Intercepted::kNo; // Unknown property, let default handling occur
809799
}
810800

@@ -813,8 +803,8 @@ Intercepted DatabaseSyncLimits::LimitsGetter(
813803
return Intercepted::kYes;
814804
}
815805

816-
int current_value =
817-
sqlite3_limit(limits->database_->Connection(), limit_id, -1);
806+
int current_value = sqlite3_limit(
807+
limits->database_->Connection(), kLimitMapping[idx].sqlite_limit_id, -1);
818808
info.GetReturnValue().Set(Integer::New(isolate, current_value));
819809
return Intercepted::kYes;
820810
}
@@ -834,9 +824,9 @@ Intercepted DatabaseSyncLimits::LimitsSetter(
834824
Isolate* isolate = env->isolate();
835825

836826
Utf8Value prop_name(isolate, property);
837-
int limit_id = GetLimitIdFromName(*prop_name);
827+
int idx = GetLimitIndexFromName(*prop_name);
838828

839-
if (limit_id < 0) {
829+
if (idx < 0) {
840830
return Intercepted::kNo;
841831
}
842832

@@ -859,14 +849,15 @@ Intercepted DatabaseSyncLimits::LimitsSetter(
859849
}
860850

861851
// Validate against compile-time maximum
862-
int max_value = GetMaxValueForLimitId(limit_id);
863-
if (new_value > max_value) {
852+
if (new_value > kLimitMapping[idx].max_value) {
864853
THROW_ERR_OUT_OF_RANGE(isolate,
865854
"Limit value exceeds compile-time maximum.");
866855
return Intercepted::kYes;
867856
}
868857

869-
sqlite3_limit(limits->database_->Connection(), limit_id, new_value);
858+
sqlite3_limit(limits->database_->Connection(),
859+
kLimitMapping[idx].sqlite_limit_id,
860+
new_value);
870861
return Intercepted::kYes;
871862
}
872863

@@ -878,9 +869,9 @@ Intercepted DatabaseSyncLimits::LimitsQuery(
878869

879870
Isolate* isolate = info.GetIsolate();
880871
Utf8Value prop_name(isolate, property);
881-
int limit_id = GetLimitIdFromName(prop_name.ToStringView());
872+
int idx = GetLimitIndexFromName(prop_name.ToStringView());
882873

883-
if (limit_id < 0) {
874+
if (idx < 0) {
884875
return Intercepted::kNo;
885876
}
886877

0 commit comments

Comments
 (0)