in e382330b925c33b29ade9a943aea8db8142b0d12 wallet: skip APS when no partial spend exists
By calling available_coins.All() and preset_inputs.All() (both are CoinsResult::All()) you are creating two new temporary vectors of COutput.
You can just iterate the original vectors, with something like:
$ git diff
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index 3dd562ba98..e09c741538 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -1254,13 +1254,16 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
bool has_partial_spend{false};
if (coin_control.m_allow_other_inputs) {
std::map<CScript, std::pair<size_t, size_t>> spk_counts; // {available, selected}
- for (const auto& coin : available_coins.All()) {
- spk_counts[coin.txout.scriptPubKey].first++;
- }
+ auto count_available_outputs = [&spk_counts](const CoinsResult& coins) {
+ for (const auto& [_, outputs] : coins.coins) {
+ for (const auto& coin : outputs) {
+ spk_counts[coin.txout.scriptPubKey].first++;
+ }
+ }
+ };
+ count_available_outputs(available_coins);
// AvailableCoins skips manually selected coins, so count them here too.
- for (const auto& coin : preset_inputs.All()) {
- spk_counts[coin.txout.scriptPubKey].first++;
- }
+ count_available_outputs(preset_inputs);
for (const auto& coin : result.GetInputSet()) {
spk_counts[coin->txout.scriptPubKey].second++;
}
You can ignore the lamda, it is just a personal preference, it is fine with me to have two loops :)