refactor: replace qLowerBound & qUpperBound with std:: upper_bound & lower_bound

This commit is contained in:
fanquake 2019-08-21 09:49:21 +08:00
parent 59373e3e94
commit 153d9dd9ac
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1
2 changed files with 7 additions and 5 deletions

View file

@ -88,7 +88,7 @@ public:
QString::fromStdString(EncodeDestination(address.dest)))); QString::fromStdString(EncodeDestination(address.dest))));
} }
} }
// qLowerBound() and qUpperBound() require our cachedAddressTable list to be sorted in asc order // std::lower_bound() and std::upper_bound() require our cachedAddressTable list to be sorted in asc order
// Even though the map is already sorted this re-sorting step is needed because the originating map // Even though the map is already sorted this re-sorting step is needed because the originating map
// is sorted by binary address, not by base58() address. // is sorted by binary address, not by base58() address.
std::sort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan()); std::sort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
@ -97,9 +97,9 @@ public:
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status) void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
{ {
// Find address / label in model // Find address / label in model
QList<AddressTableEntry>::iterator lower = qLowerBound( QList<AddressTableEntry>::iterator lower = std::lower_bound(
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan()); cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
QList<AddressTableEntry>::iterator upper = qUpperBound( QList<AddressTableEntry>::iterator upper = std::upper_bound(
cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan()); cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
int lowerIndex = (lower - cachedAddressTable.begin()); int lowerIndex = (lower - cachedAddressTable.begin());
int upperIndex = (upper - cachedAddressTable.begin()); int upperIndex = (upper - cachedAddressTable.begin());

View file

@ -17,6 +17,8 @@
#include <interfaces/handler.h> #include <interfaces/handler.h>
#include <uint256.h> #include <uint256.h>
#include <algorithm>
#include <QColor> #include <QColor>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
@ -93,9 +95,9 @@ public:
qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status); qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status);
// Find bounds of this transaction in model // Find bounds of this transaction in model
QList<TransactionRecord>::iterator lower = qLowerBound( QList<TransactionRecord>::iterator lower = std::lower_bound(
cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
QList<TransactionRecord>::iterator upper = qUpperBound( QList<TransactionRecord>::iterator upper = std::upper_bound(
cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan()); cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
int lowerIndex = (lower - cachedWallet.begin()); int lowerIndex = (lower - cachedWallet.begin());
int upperIndex = (upper - cachedWallet.begin()); int upperIndex = (upper - cachedWallet.begin());