@@ -166,19 +166,11 @@ Local<DictionaryTemplate> getLazyIterTemplate(Environment* env) {
166166}
167167} // namespace
168168
169- // Helper function to find limit info from JS property name
170- static constexpr const LimitInfo* GetLimitInfoFromName (std::string_view name) {
171- for (const auto & info : kLimitMapping ) {
172- if (name == info.js_name ) {
173- return &info;
174- }
175- }
176- return nullptr ;
177- }
178-
179- static constexpr const StatusInfo* GetStatusInfoFromName (
180- std::string_view name) {
181- for (const auto & info : kStatusMapping ) {
169+ // Helper function to look up a mapping entry by its JS-facing name
170+ template <typename T, size_t N>
171+ static constexpr const T* FindByJsName (const std::array<T, N>& mapping,
172+ std::string_view name) {
173+ for (const auto & info : mapping) {
182174 if (name == info.js_name ) {
183175 return &info;
184176 }
@@ -792,7 +784,8 @@ Intercepted DatabaseSyncLimits::LimitsGetter(
792784 Isolate* isolate = env->isolate ();
793785
794786 Utf8Value prop_name (isolate, property);
795- const LimitInfo* limit_info = GetLimitInfoFromName (prop_name.ToStringView ());
787+ const LimitInfo* limit_info =
788+ FindByJsName (kLimitMapping , prop_name.ToStringView ());
796789
797790 if (limit_info == nullptr ) {
798791 return Intercepted::kNo ; // Unknown property, let default handling occur
@@ -824,7 +817,8 @@ Intercepted DatabaseSyncLimits::LimitsSetter(
824817 Isolate* isolate = env->isolate ();
825818
826819 Utf8Value prop_name (isolate, property);
827- const LimitInfo* limit_info = GetLimitInfoFromName (prop_name.ToStringView ());
820+ const LimitInfo* limit_info =
821+ FindByJsName (kLimitMapping , prop_name.ToStringView ());
828822
829823 if (limit_info == nullptr ) {
830824 return Intercepted::kNo ;
@@ -872,7 +866,8 @@ Intercepted DatabaseSyncLimits::LimitsQuery(
872866
873867 Isolate* isolate = info.GetIsolate ();
874868 Utf8Value prop_name (isolate, property);
875- const LimitInfo* limit_info = GetLimitInfoFromName (prop_name.ToStringView ());
869+ const LimitInfo* limit_info =
870+ FindByJsName (kLimitMapping , prop_name.ToStringView ());
876871
877872 if (!limit_info) {
878873 return Intercepted::kNo ;
@@ -3335,7 +3330,8 @@ void StatementSync::Stat(const FunctionCallbackInfo<Value>& args) {
33353330 }
33363331
33373332 Utf8Value counter (isolate, args[0 ].As <String>());
3338- const StatusInfo* status_info = GetStatusInfoFromName (counter.ToStringView ());
3333+ const StatusInfo* status_info =
3334+ FindByJsName (kStatusMapping , counter.ToStringView ());
33393335 if (status_info == nullptr ) {
33403336 THROW_ERR_INVALID_ARG_VALUE (
33413337 isolate, " The \" counter\" argument is not a valid statistic name." );
0 commit comments