mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
Merge #17746: refactor: rpc: Remove vector copy from listtransactions
25bc17fceb
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 ACK25bc17fceb
. Just comment and commit message tweaks since last review Tree-SHA512: 87906561e3accdbdb0f4a8194cbcd76ea53ae53d0ce135b90bc54a5f77e300b14ef08505e7daf1fe52426f135442a743da5a027416a769bd454922357cebe7c0
This commit is contained in:
commit
470664f2b7
1 changed files with 4 additions and 17 deletions
|
@ -1500,23 +1500,10 @@ UniValue listtransactions(const JSONRPCRequest& request)
|
|||
if ((nFrom + nCount) > (int)ret.size())
|
||||
nCount = ret.size() - nFrom;
|
||||
|
||||
std::vector<UniValue> arrTmp = ret.getValues();
|
||||
|
||||
std::vector<UniValue>::iterator first = arrTmp.begin();
|
||||
std::advance(first, nFrom);
|
||||
std::vector<UniValue>::iterator last = arrTmp.begin();
|
||||
std::advance(last, nFrom+nCount);
|
||||
|
||||
if (last != arrTmp.end()) arrTmp.erase(last, arrTmp.end());
|
||||
if (first != arrTmp.begin()) arrTmp.erase(arrTmp.begin(), first);
|
||||
|
||||
std::reverse(arrTmp.begin(), arrTmp.end()); // Return oldest to newest
|
||||
|
||||
ret.clear();
|
||||
ret.setArray();
|
||||
ret.push_backV(arrTmp);
|
||||
|
||||
return ret;
|
||||
const std::vector<UniValue>& txs = ret.getValues();
|
||||
UniValue result{UniValue::VARR};
|
||||
result.push_backV({ txs.rend() - nFrom - nCount, txs.rend() - nFrom }); // Return oldest to newest
|
||||
return result;
|
||||
}
|
||||
|
||||
static UniValue listsinceblock(const JSONRPCRequest& request)
|
||||
|
|
Loading…
Reference in a new issue