From b2ad5302ce81180336e6f3ae097860e7d7903f74 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 12 Dec 2023 03:58:08 +0700 Subject: [PATCH] refactor: simplify comparator in rpc/governance --- src/rpc/governance.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index a0e06fa070..f8744b28c5 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -271,16 +271,13 @@ static UniValue gobject_list_prepared(const JSONRPCRequest& request) std::vector vecObjects = wallet->GetGovernanceObjects(); // Sort the vector by the object creation time/hex data std::sort(vecObjects.begin(), vecObjects.end(), [](const Governance::Object* a, const Governance::Object* b) { - bool fGreater = a->time > b->time; - bool fEqual = a->time == b->time; - bool fHexGreater = a->GetDataAsHexString() > b->GetDataAsHexString(); - return fGreater || (fEqual && fHexGreater); + if (a->time != b->time) return a->time < b->time; + return a->GetDataAsHexString() < b->GetDataAsHexString(); }); UniValue jsonArray(UniValue::VARR); - auto it = vecObjects.rbegin() + std::max(0, vecObjects.size() - nCount); - while (it != vecObjects.rend()) { - jsonArray.push_back((*it++)->ToJson()); + for (auto it = vecObjects.begin() + std::max(0, vecObjects.size() - nCount); it != vecObjects.end(); ++it) { + jsonArray.push_back((*it)->ToJson()); } return jsonArray;