refactor: make a few additional things use std::string_view (#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 <126646+laanwj@users.noreply.github.com>
This commit is contained in:
PastaPastaPasta 2024-02-19 12:22:53 -06:00 committed by GitHub
parent 0f0c53aed3
commit 95b15fdda2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 19 deletions

View File

@ -28,20 +28,17 @@
namespace llmq
{
static const std::string INPUTLOCK_REQUESTID_PREFIX = "inlock";
static const std::string ISLOCK_REQUESTID_PREFIX = "islock";
static const std::string_view INPUTLOCK_REQUESTID_PREFIX = "inlock";
static const std::string_view ISLOCK_REQUESTID_PREFIX = "islock";
static const std::string DB_ISLOCK_BY_HASH = "is_i";
static const std::string DB_HASH_BY_TXID = "is_tx";
static const std::string DB_HASH_BY_OUTPOINT = "is_in";
static const std::string DB_MINED_BY_HEIGHT_AND_HASH = "is_m";
static const std::string DB_ARCHIVED_BY_HEIGHT_AND_HASH = "is_a1";
static const std::string DB_ARCHIVED_BY_HASH = "is_a2";
static const std::string_view DB_ISLOCK_BY_HASH = "is_i";
static const std::string_view DB_HASH_BY_TXID = "is_tx";
static const std::string_view DB_HASH_BY_OUTPOINT = "is_in";
static const std::string_view DB_MINED_BY_HEIGHT_AND_HASH = "is_m";
static const std::string_view DB_ARCHIVED_BY_HEIGHT_AND_HASH = "is_a1";
static const std::string_view DB_ARCHIVED_BY_HASH = "is_a2";
static const std::string DB_VERSION = "is_v";
const int CInstantSendDb::CURRENT_VERSION;
const uint8_t CInstantSendLock::CURRENT_VERSION;
static const std::string_view DB_VERSION = "is_v";
std::unique_ptr<CInstantSendManager> quorumInstantSendManager;
@ -73,7 +70,7 @@ void CInstantSendDb::Upgrade(const CTxMemPool& mempool)
CInstantSendLock islock;
auto it = std::unique_ptr<CDBIterator>(db->NewIterator());
auto firstKey = std::make_tuple(DB_ISLOCK_BY_HASH, uint256());
auto firstKey = std::make_tuple(std::string{DB_ISLOCK_BY_HASH}, uint256());
it->Seek(firstKey);
decltype(firstKey) curKey;
@ -142,9 +139,9 @@ void CInstantSendDb::RemoveInstantSendLock(CDBBatch& batch, const uint256& hash,
}
}
static std::tuple<std::string, uint32_t, uint256> BuildInversedISLockKey(const std::string& k, int nHeight, const uint256& islockHash)
static std::tuple<std::string, uint32_t, uint256> BuildInversedISLockKey(std::string_view k, int nHeight, const uint256& islockHash)
{
return std::make_tuple(k, htobe32(std::numeric_limits<uint32_t>::max() - nHeight), islockHash);
return std::make_tuple(std::string{k}, htobe32(std::numeric_limits<uint32_t>::max() - nHeight), islockHash);
}
void CInstantSendDb::WriteInstantSendLockMined(const uint256& hash, int nHeight)
@ -302,7 +299,7 @@ size_t CInstantSendDb::GetInstantSendLockCount() const
{
LOCK(cs_db);
auto it = std::unique_ptr<CDBIterator>(db->NewIterator());
auto firstKey = std::make_tuple(DB_ISLOCK_BY_HASH, uint256());
auto firstKey = std::make_tuple(std::string{DB_ISLOCK_BY_HASH}, uint256());
it->Seek(firstKey);
@ -382,7 +379,7 @@ std::vector<uint256> CInstantSendDb::GetInstantSendLocksByParent(const uint256&
{
AssertLockHeld(cs_db);
auto it = std::unique_ptr<CDBIterator>(db->NewIterator());
auto firstKey = std::make_tuple(DB_HASH_BY_OUTPOINT, COutPoint(parent, 0));
auto firstKey = std::make_tuple(std::string{DB_HASH_BY_OUTPOINT}, COutPoint(parent, 0));
it->Seek(firstKey);
std::vector<uint256> result;
@ -751,7 +748,7 @@ void CInstantSendManager::HandleNewInstantSendLockRecoveredSig(const llmq::CReco
pendingInstantSendLocks.emplace(hash, std::make_pair(-1, islock));
}
PeerMsgRet CInstantSendManager::ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, const std::string& msg_type, CDataStream& vRecv)
PeerMsgRet CInstantSendManager::ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, std::string_view msg_type, CDataStream& vRecv)
{
if (IsInstantSendEnabled() && msg_type == NetMsgType::ISDLOCK) {
if (m_peerman == nullptr) {

View File

@ -313,7 +313,7 @@ public:
void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) override LOCKS_EXCLUDED(cs_inputReqests, cs_creating);
PeerMsgRet ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, const std::string& msg_type, CDataStream& vRecv);
PeerMsgRet ProcessMessage(const CNode& pfrom, gsl::not_null<PeerManager*> peerman, std::string_view msg_type, CDataStream& vRecv);
void TransactionAddedToMempool(const CTransactionRef& tx) LOCKS_EXCLUDED(cs_pendingLocks);
void TransactionRemovedFromMempool(const CTransactionRef& tx);