Skip to content

Commit 1780961

Browse files
committed
revert: bitcoin#25464 (Reduce Univalue push_backV peak memory usage in listtransactions)
reverts: - 001d7ba.
1 parent f648039 commit 1780961

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

src/univalue/include/univalue.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ class UniValue {
111111
return push_back(tmpVal);
112112
}
113113
bool push_backV(const std::vector<UniValue>& vec);
114-
template <class It>
115-
bool push_backV(It first, It last);
116114

117115
void __pushKV(const std::string& key, const UniValue& val);
118116
bool pushKV(const std::string& key, const UniValue& val);
@@ -182,14 +180,6 @@ class UniValue {
182180
friend const UniValue& find_value( const UniValue& obj, const std::string& name);
183181
};
184182

185-
template <class It>
186-
bool UniValue::push_backV(It first, It last)
187-
{
188-
if (typ != VARR) return false;
189-
values.insert(values.end(), first, last);
190-
return true;
191-
}
192-
193183
enum jtokentype {
194184
JTOK_ERR = -1,
195185
JTOK_NONE = 0, // eof

src/wallet/rpc/transactions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,11 @@ static void MaybePushAddress(UniValue & entry, const CTxDestination &dest)
329329
* @param wtx The wallet transaction.
330330
* @param nMinDepth The minimum confirmation depth.
331331
* @param fLong Whether to include the JSON version of the transaction.
332-
* @param ret The vector into which the result is stored.
332+
* @param ret The UniValue into which the result is stored.
333333
* @param filter_ismine The "is mine" filter flags.
334334
* @param filter_label Optional label string to filter incoming transactions.
335335
*/
336-
template <class Vec>
337-
static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nMinDepth, bool fLong, Vec& ret, const isminefilter& filter_ismine, const std::string* filter_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
336+
static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nMinDepth, bool fLong, UniValue& ret, const isminefilter& filter_ismine, const std::string* filter_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
338337
{
339338
CAmount nFee;
340339
std::list<COutputEntry> listReceived;
@@ -521,7 +520,8 @@ RPCHelpMan listtransactions()
521520
if (nFrom < 0)
522521
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from");
523522

524-
std::vector<UniValue> ret;
523+
UniValue ret(UniValue::VARR);
524+
525525
{
526526
LOCK(pwallet->cs_wallet);
527527

@@ -543,9 +543,9 @@ RPCHelpMan listtransactions()
543543
if ((nFrom + nCount) > (int)ret.size())
544544
nCount = ret.size() - nFrom;
545545

546-
auto txs_rev_it{std::make_move_iterator(ret.rend())};
546+
const std::vector<UniValue>& txs = ret.getValues();
547547
UniValue result{UniValue::VARR};
548-
result.push_backV(txs_rev_it - nFrom - nCount, txs_rev_it - nFrom); // Return oldest to newest
548+
result.push_backV({ txs.rend() - nFrom - nCount, txs.rend() - nFrom }); // Return oldest to newest
549549
return result;
550550
},
551551
};

0 commit comments

Comments
 (0)