From 9c5e4ab0380e2ce4573c2bab8b17aa7216d351a1 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 22 Apr 2025 09:41:54 -0400 Subject: [PATCH 1/6] src: use ranges library (C++20) to simplify code --- src/node_options-inl.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 24954e0b583834..7361aa39c59fc1 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -4,6 +4,7 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include +#include #include "node_options.h" #include "util.h" @@ -394,14 +395,13 @@ void OptionsParser::Parse( implied_name.insert(2, "no-"); } auto implications = implications_.equal_range(implied_name); - for (auto imp = implications.first; imp != implications.second; ++imp) { - if (imp->second.type == kV8Option) { - v8_args->push_back(imp->second.name); - } else { - *imp->second.target_field->template Lookup(options) = - imp->second.target_value; - } - } + std::ranges::for_each(implications | std::views::values, [&](const auto& value) { + if (value.type == kV8Option) { + v8_args->push_back(value.name); + } else { + *value.target_field->template Lookup(options) = value.target_value; + } + }); } if (it == options_.end()) { From 1c10b77529cdebdeee5d39ee06566994a3914372 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 22 Apr 2025 11:40:39 -0400 Subject: [PATCH 2/6] breaking long lines --- src/node_options-inl.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 7361aa39c59fc1..654aa5ed1692b9 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -395,11 +395,13 @@ void OptionsParser::Parse( implied_name.insert(2, "no-"); } auto implications = implications_.equal_range(implied_name); - std::ranges::for_each(implications | std::views::values, [&](const auto& value) { + std::ranges::for_each( + implications | std::views::values, [&](const auto& value) { if (value.type == kV8Option) { - v8_args->push_back(value.name); + v8_args->push_back(value.name); } else { - *value.target_field->template Lookup(options) = value.target_value; + *value.target_field->template Lookup(options) = + value.target_value; } }); } From 24b932da85a2b969e113fc80107e3c0d196db05f Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 22 Apr 2025 13:41:34 -0400 Subject: [PATCH 3/6] adding missing algorithm header --- src/node_options-inl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 654aa5ed1692b9..2a2fd5a02eaa27 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -3,6 +3,7 @@ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS +#include #include #include #include "node_options.h" From 2a35e7ec169dd206ce15a875d4a8ff6a99aa7f5b Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Wed, 23 Apr 2025 19:32:08 -0400 Subject: [PATCH 4/6] lint --- src/node_options-inl.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 2a2fd5a02eaa27..a310236ba68f24 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -395,16 +395,16 @@ void OptionsParser::Parse( // Implications for negated options are defined with "--no-". implied_name.insert(2, "no-"); } - auto implications = implications_.equal_range(implied_name); + auto [f, l] = implications_.equal_range(implied_name); std::ranges::for_each( - implications | std::views::values, [&](const auto& value) { - if (value.type == kV8Option) { - v8_args->push_back(value.name); - } else { - *value.target_field->template Lookup(options) = - value.target_value; - } - }); + std::ranges::subrange(f,l) | std::views::values, [&](const auto& value) { + if (value.type == kV8Option) { + v8_args->push_back(value.name); + } else { + *value.target_field->template Lookup(options) = + value.target_value; + } + }); } if (it == options_.end()) { From 4d30380761e6f6916fea3a62f7f736022e94672c Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Wed, 23 Apr 2025 19:39:20 -0400 Subject: [PATCH 5/6] long line --- src/node_options-inl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index a310236ba68f24..2d1df883c3b96d 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -397,7 +397,8 @@ void OptionsParser::Parse( } auto [f, l] = implications_.equal_range(implied_name); std::ranges::for_each( - std::ranges::subrange(f,l) | std::views::values, [&](const auto& value) { + std::ranges::subrange(f, l) | std::views::values, + [&](const auto& value) { if (value.type == kV8Option) { v8_args->push_back(value.name); } else { From 8289bba13bb9564d267b73bc87cdd5cc49fa8b71 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Wed, 23 Apr 2025 19:40:15 -0400 Subject: [PATCH 6/6] relint --- src/node_options-inl.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 2d1df883c3b96d..55078af457fc7c 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -396,16 +396,15 @@ void OptionsParser::Parse( implied_name.insert(2, "no-"); } auto [f, l] = implications_.equal_range(implied_name); - std::ranges::for_each( - std::ranges::subrange(f, l) | std::views::values, - [&](const auto& value) { - if (value.type == kV8Option) { - v8_args->push_back(value.name); - } else { - *value.target_field->template Lookup(options) = - value.target_value; - } - }); + std::ranges::for_each(std::ranges::subrange(f, l) | std::views::values, + [&](const auto& value) { + if (value.type == kV8Option) { + v8_args->push_back(value.name); + } else { + *value.target_field->template Lookup( + options) = value.target_value; + } + }); } if (it == options_.end()) {