Skip to content

Commit 25bc17f

Browse files
committed
refactor: rpc: Remove vector copy from listtransactions
No change in behavior.
1 parent ddecb67 commit 25bc17f

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
@@ -1491,23 +1491,10 @@ UniValue listtransactions(const JSONRPCRequest& request)
14911491
if ((nFrom + nCount) > (int)ret.size())
14921492
nCount = ret.size() - nFrom;
14931493

1494-
std::vector<UniValue> arrTmp = ret.getValues();
1495-
1496-
std::vector<UniValue>::iterator first = arrTmp.begin();
1497-
std::advance(first, nFrom);
1498-
std::vector<UniValue>::iterator last = arrTmp.begin();
1499-
std::advance(last, nFrom+nCount);
1500-
1501-
if (last != arrTmp.end()) arrTmp.erase(last, arrTmp.end());
1502-
if (first != arrTmp.begin()) arrTmp.erase(arrTmp.begin(), first);
1503-
1504-
std::reverse(arrTmp.begin(), arrTmp.end()); // Return oldest to newest
1505-
1506-
ret.clear();
1507-
ret.setArray();
1508-
ret.push_backV(arrTmp);
1509-
1510-
return ret;
1494+
const std::vector<UniValue>& txs = ret.getValues();
1495+
UniValue result{UniValue::VARR};
1496+
result.push_backV({ txs.rend() - nFrom - nCount, txs.rend() - nFrom }); // Return oldest to newest
1497+
return result;
15111498
}
15121499

15131500
static UniValue listsinceblock(const JSONRPCRequest& request)

0 commit comments

Comments
 (0)