Skip to content

Commit 470664f

Browse files
committed
Merge #17746: refactor: rpc: Remove vector copy from listtransactions
25bc17f refactor: rpc: Remove vector copy from listtransactions (João Barbosa) Pull request description: Current approach - copy accumulated `ret` vector to `arrTmp` - drop unnecessary elements from `arrTmp` - reverse `arrTmp` - clear `ret` - copy `arrTmp` to the `ret` New approach - create a vector from the accumulated `ret` with just the necessary elements already reversed - copy it to the result This PR doesn't change behavior. ACKs for top commit: ryanofsky: Code review ACK 25bc17f. Just comment and commit message tweaks since last review Tree-SHA512: 87906561e3accdbdb0f4a8194cbcd76ea53ae53d0ce135b90bc54a5f77e300b14ef08505e7daf1fe52426f135442a743da5a027416a769bd454922357cebe7c0
2 parents 0c20809 + 25bc17f commit 470664f

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,23 +1500,10 @@ UniValue listtransactions(const JSONRPCRequest& request)
15001500
if ((nFrom + nCount) > (int)ret.size())
15011501
nCount = ret.size() - nFrom;
15021502

1503-
std::vector<UniValue> arrTmp = ret.getValues();
1504-
1505-
std::vector<UniValue>::iterator first = arrTmp.begin();
1506-
std::advance(first, nFrom);
1507-
std::vector<UniValue>::iterator last = arrTmp.begin();
1508-
std::advance(last, nFrom+nCount);
1509-
1510-
if (last != arrTmp.end()) arrTmp.erase(last, arrTmp.end());
1511-
if (first != arrTmp.begin()) arrTmp.erase(arrTmp.begin(), first);
1512-
1513-
std::reverse(arrTmp.begin(), arrTmp.end()); // Return oldest to newest
1514-
1515-
ret.clear();
1516-
ret.setArray();
1517-
ret.push_backV(arrTmp);
1518-
1519-
return ret;
1503+
const std::vector<UniValue>& txs = ret.getValues();
1504+
UniValue result{UniValue::VARR};
1505+
result.push_backV({ txs.rend() - nFrom - nCount, txs.rend() - nFrom }); // Return oldest to newest
1506+
return result;
15201507
}
15211508

15221509
static UniValue listsinceblock(const JSONRPCRequest& request)

0 commit comments

Comments
 (0)