Skip to content

Commit 125715b

Browse files
committed
replace hardcoded limit size with constexpr variable for better maintainability
1 parent 854f486 commit 125715b

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/node_sqlite.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct LimitInfo {
147147
int sqlite_limit_id;
148148
};
149149

150-
static constexpr std::array<LimitInfo, 11> kLimitMapping = {{
150+
static constexpr std::array<LimitInfo, kNumSqliteLimits> kLimitMapping = {{
151151
{"length", SQLITE_LIMIT_LENGTH},
152152
{"sqlLength", SQLITE_LIMIT_SQL_LENGTH},
153153
{"column", SQLITE_LIMIT_COLUMN},
@@ -754,7 +754,7 @@ Intercepted DatabaseSyncLimits::LimitsGetter(
754754
Utf8Value prop_name(isolate, property);
755755
const LimitInfo* limit_info = GetLimitInfoFromName(prop_name.ToStringView());
756756

757-
if (!limit_info) {
757+
if (limit_info == nullptr) {
758758
return Intercepted::kNo; // Unknown property, let default handling occur
759759
}
760760

@@ -848,12 +848,12 @@ void DatabaseSyncLimits::LimitsEnumerator(
848848
Isolate* isolate = info.GetIsolate();
849849
LocalVector<Value> names(isolate);
850850

851-
for (size_t i = 0; i < kLimitMapping.size(); ++i) {
851+
for (const auto& mapping : kLimitMapping) {
852852
Local<String> name;
853853
if (!String::NewFromUtf8(isolate,
854-
kLimitMapping[i].js_name.data(),
854+
mapping.js_name.data(),
855855
NewStringType::kNormal,
856-
kLimitMapping[i].js_name.size())
856+
mapping.js_name.size())
857857
.ToLocal(&name)) {
858858
return;
859859
}

src/node_sqlite.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
namespace node {
1717
namespace sqlite {
1818

19+
constexpr size_t kNumSqliteLimits = 11;
20+
1921
class DatabaseOpenConfiguration {
2022
public:
2123
explicit DatabaseOpenConfiguration(std::string&& location)
@@ -73,7 +75,7 @@ class DatabaseOpenConfiguration {
7375
initial_limits_.at(limit_id) = value;
7476
}
7577

76-
inline const std::array<std::optional<int>, SQLITE_LIMIT_TRIGGER_DEPTH + 1>&
78+
inline const std::array<std::optional<int>, kNumSqliteLimits>&
7779
initial_limits() const {
7880
return initial_limits_;
7981
}
@@ -89,7 +91,7 @@ class DatabaseOpenConfiguration {
8991
bool allow_bare_named_params_ = true;
9092
bool allow_unknown_named_params_ = false;
9193
bool defensive_ = false;
92-
std::array<std::optional<int>, SQLITE_LIMIT_TRIGGER_DEPTH + 1>
94+
std::array<std::optional<int>, kNumSqliteLimits>
9395
initial_limits_;
9496
};
9597

0 commit comments

Comments
 (0)