What changed, and why it matters
This is a small performance cleanup in Monero's wallet code. It replaces two unnecessary copies of transaction lists with references, and switches one lookup from a two-step 'check then fetch' to a single map lookup. There is no security issue visible in the change.
No security action needed; this is a routine performance refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit makes three micro-optimizations in src/wallet/wallet2.cpp: (1) in expand_subaddresses(), it uses std::map::find() once instead of count() followed by at(), avoiding two tree traversals; (2-3) in get_rings(), it iterates m_confirmed_txs and m_unconfirmed_txs by const reference instead of by value, removing copies of map elements. These are purely local efficiency improvements with no behavioral or security-relevant change.
Changed components
src/wallet/wallet2.cppInspect captured patch +4 / −3
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index fadfb9f..88b0737 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -1662,7 +1662,8 @@ void wallet2::expand_subaddresses(const cryptonote::subaddress_index& index)
const std::size_t n_minor_labels = (major < m_subaddress_labels.size()) ? m_subaddress_labels.at(major).size() : 0;
const std::uint32_t minor_base = std::max<std::uint32_t>(n_minor_labels, 1) - 1;
const std::uint32_t minor_end = get_subaddress_clamped_sum(minor_base, m_subaddress_lookahead_minor);
- const std::uint32_t minor_begin = lowest_missing_minor.count(major) ? lowest_missing_minor.at(major) : 0;
+ const auto lowest_missing_minor_it = lowest_missing_minor.find(major);
+ const std::uint32_t minor_begin = lowest_missing_minor_it != lowest_missing_minor.end() ? lowest_missing_minor_it->second : 0;
if (minor_begin >= minor_end)
continue;
const std::vector<crypto::public_key> pkeys
@@ -8927,7 +8928,7 @@ bool wallet2::get_rings(const crypto::chacha_key &key, const std::vector<crypto:
bool wallet2::get_rings(const crypto::hash &txid, std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> &outs)
{
- for (auto i: m_confirmed_txs)
+ for (const auto &i: m_confirmed_txs)
{
if (txid == i.first)
{
@@ -8936,7 +8937,7 @@ bool wallet2::get_rings(const crypto::hash &txid, std::vector<std::pair<crypto::
return true;
}
}
- for (auto i: m_unconfirmed_txs)
+ for (const auto &i: m_unconfirmed_txs)
{
if (txid == i.first)
{
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.