From 7e974f474e2fbc764b1d35d207f19f2d880bc853 Mon Sep 17 00:00:00 2001 From: Hodlinator <172445034+hodlinator@users.noreply.github.com> Date: Sat, 29 Mar 2025 20:43:48 +0100 Subject: [PATCH] descriptors refactor: Use range-for and limit scope of seen_multipath * Range-for avoids ++i/i++ debate and decreases linecount. * seen_multipath is only used if multipath_segment_index hasn't already been set. Rename it to seen_substitutes to better describe what it does, now that the context implies its involved in multipath. --- src/script/descriptor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index ecd315407eb..68a2cc90a13 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -1442,7 +1442,6 @@ std::optional ParseKeyPathNum(std::span elem, bool& apostr KeyPath path; std::optional multipath_segment_index; std::vector multipath_values; - std::unordered_set seen_multipath; for (size_t i = 1; i < split.size(); ++i) { const std::span& elem = split[i]; @@ -1465,10 +1464,11 @@ std::optional ParseKeyPathNum(std::span elem, bool& apostr return false; } + std::unordered_set seen_substitutes; for (const auto& num : nums) { const auto& op_num = ParseKeyPathNum(num, apostrophe, error); if (!op_num) return false; - auto [_, inserted] = seen_multipath.insert(*op_num); + auto [_, inserted] = seen_substitutes.insert(*op_num); if (!inserted) { error = strprintf("Duplicated key path value %u in multipath specifier", *op_num); return false; @@ -1489,9 +1489,9 @@ std::optional ParseKeyPathNum(std::span elem, bool& apostr out.emplace_back(std::move(path)); } else { // Replace the multipath placeholder with each value while generating paths - for (size_t i = 0; i < multipath_values.size(); i++) { + for (uint32_t substitute : multipath_values) { KeyPath branch_path = path; - branch_path[*multipath_segment_index] = multipath_values[i]; + branch_path[*multipath_segment_index] = substitute; out.emplace_back(std::move(branch_path)); } }