Skip to content

Commit 7e974f4

Browse files
committed
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.
1 parent 99a92ef commit 7e974f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/script/descriptor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,6 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
14421442
KeyPath path;
14431443
std::optional<size_t> multipath_segment_index;
14441444
std::vector<uint32_t> multipath_values;
1445-
std::unordered_set<uint32_t> seen_multipath;
14461445

14471446
for (size_t i = 1; i < split.size(); ++i) {
14481447
const std::span<const char>& elem = split[i];
@@ -1465,10 +1464,11 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
14651464
return false;
14661465
}
14671466

1467+
std::unordered_set<uint32_t> seen_substitutes;
14681468
for (const auto& num : nums) {
14691469
const auto& op_num = ParseKeyPathNum(num, apostrophe, error);
14701470
if (!op_num) return false;
1471-
auto [_, inserted] = seen_multipath.insert(*op_num);
1471+
auto [_, inserted] = seen_substitutes.insert(*op_num);
14721472
if (!inserted) {
14731473
error = strprintf("Duplicated key path value %u in multipath specifier", *op_num);
14741474
return false;
@@ -1489,9 +1489,9 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
14891489
out.emplace_back(std::move(path));
14901490
} else {
14911491
// Replace the multipath placeholder with each value while generating paths
1492-
for (size_t i = 0; i < multipath_values.size(); i++) {
1492+
for (uint32_t substitute : multipath_values) {
14931493
KeyPath branch_path = path;
1494-
branch_path[*multipath_segment_index] = multipath_values[i];
1494+
branch_path[*multipath_segment_index] = substitute;
14951495
out.emplace_back(std::move(branch_path));
14961496
}
14971497
}

0 commit comments

Comments
 (0)