Skip to content

Commit 95b15fd

Browse files
refactor: make a few additional things use std::string_view (dashpay#5874)
## Issue being fixed or feature implemented Use string view where possible ## What was done? ## How Has This Been Tested? Building ## Breaking Changes None ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ Co-authored-by: laanwj <[email protected]>
1 parent 0f0c53a commit 95b15fd

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

src/llmq/instantsend.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,17 @@
2828
namespace llmq
2929
{
3030

31-
static const std::string INPUTLOCK_REQUESTID_PREFIX = "inlock";
32-
static const std::string ISLOCK_REQUESTID_PREFIX = "islock";
31+
static const std::string_view INPUTLOCK_REQUESTID_PREFIX = "inlock";
32+
static const std::string_view ISLOCK_REQUESTID_PREFIX = "islock";
3333

34-
static const std::string DB_ISLOCK_BY_HASH = "is_i";
35-
static const std::string DB_HASH_BY_TXID = "is_tx";
36-
static const std::string DB_HASH_BY_OUTPOINT = "is_in";
37-
static const std::string DB_MINED_BY_HEIGHT_AND_HASH = "is_m";
38-
static const std::string DB_ARCHIVED_BY_HEIGHT_AND_HASH = "is_a1";
39-
static const std::string DB_ARCHIVED_BY_HASH = "is_a2";
34+
static const std::string_view DB_ISLOCK_BY_HASH = "is_i";
35+
static const std::string_view DB_HASH_BY_TXID = "is_tx";
36+
static const std::string_view DB_HASH_BY_OUTPOINT = "is_in";
37+
static const std::string_view DB_MINED_BY_HEIGHT_AND_HASH = "is_m";
38+
static const std::string_view DB_ARCHIVED_BY_HEIGHT_AND_HASH = "is_a1";
39+
static const std::string_view DB_ARCHIVED_BY_HASH = "is_a2";
4040

41-
static const std::string DB_VERSION = "is_v";
42-
43-
const int CInstantSendDb::CURRENT_VERSION;
44-
const uint8_t CInstantSendLock::CURRENT_VERSION;
41+
static const std::string_view DB_VERSION = "is_v";
4542

4643
std::unique_ptr<CInstantSendManager> quorumInstantSendManager;
4744

@@ -73,7 +70,7 @@ void CInstantSendDb::Upgrade(const CTxMemPool& mempool)
7370
CInstantSendLock islock;
7471

7572
auto it = std::unique_ptr<CDBIterator>(db->NewIterator());
76-
auto firstKey = std::make_tuple(DB_ISLOCK_BY_HASH, uint256());
73+
auto firstKey = std::make_tuple(std::string{DB_ISLOCK_BY_HASH}, uint256());
7774
it->Seek(firstKey);
7875
decltype(firstKey) curKey;
7976

@@ -142,9 +139,9 @@ void CInstantSendDb::RemoveInstantSendLock(CDBBatch& batch, const uint256& hash,
142139
}
143140
}
144141

145-
static std::tuple<std::string, uint32_t, uint256> BuildInversedISLockKey(const std::string& k, int nHeight, const uint256& islockHash)
142+
static std::tuple<std::string, uint32_t, uint256> BuildInversedISLockKey(std::string_view k, int nHeight, const uint256& islockHash)
146143
{
147-
return std::make_tuple(k, htobe32(std::numeric_limits<uint32_t>::max() - nHeight), islockHash);
144+
return std::make_tuple(std::string{k}, htobe32(std::numeric_limits<uint32_t>::max() - nHeight), islockHash);
148145
}
149146

150147
void CInstantSendDb::WriteInstantSendLockMined(const uint256& hash, int nHeight)
@@ -302,7 +299,7 @@ size_t CInstantSendDb::GetInstantSendLockCount() const
302299
{
303300
LOCK(cs_db);
304301
auto it = std::unique_ptr<CDBIterator>(db->NewIterator());
305-
auto firstKey = std::make_tuple(DB_ISLOCK_BY_HASH, uint256());
302+
auto firstKey = std::make_tuple(std::string{DB_ISLOCK_BY_HASH}, uint256());
306303

307304
it->Seek(firstKey);
308305

@@ -382,7 +379,7 @@ std::vector<uint256> CInstantSendDb::GetInstantSendLocksByParent(const uint256&
382379
{
383380
AssertLockHeld(cs_db);
384381
auto it = std::unique_ptr<CDBIterator>(db->NewIterator());
385-
auto firstKey = std::make_tuple(DB_HASH_BY_OUTPOINT, COutPoint(parent, 0));
382+
auto firstKey = std::make_tuple(std::string{DB_HASH_BY_OUTPOINT}, COutPoint(parent, 0));
386383
it->Seek(firstKey);
387384

388385
std::vector<uint256> result;
@@ -751,7 +748,7 @@ void CInstantSendManager::HandleNewInstantSendLockRecoveredSig(const llmq::CReco
751748
pendingInstantSendLocks.emplace(hash, std::make_pair(-1, islock));
752749
}
753750

754-
PeerMsgRet CInstantSendManager::ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, const std::string& msg_type, CDataStream& vRecv)
751+
PeerMsgRet CInstantSendManager::ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, std::string_view msg_type, CDataStream& vRecv)
755752
{
756753
if (IsInstantSendEnabled() && msg_type == NetMsgType::ISDLOCK) {
757754
if (m_peerman == nullptr) {

src/llmq/instantsend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class CInstantSendManager : public CRecoveredSigsListener
313313

314314
void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override LOCKS_EXCLUDED(cs_inputReqests, cs_creating);
315315

316-
PeerMsgRet ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, const std::string& msg_type, CDataStream& vRecv);
316+
PeerMsgRet ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, std::string_view msg_type, CDataStream& vRecv);
317317

318318
void TransactionAddedToMempool(const CTransactionRef& tx) LOCKS_EXCLUDED(cs_pendingLocks);
319319
void TransactionRemovedFromMempool(const CTransactionRef& tx);

0 commit comments

Comments
 (0)