Skip to content

Commit

Permalink
Merge pull request #28 from THETCR/clang-tidy
Browse files Browse the repository at this point in the history
[CORE] Clang-Tidy: modernize, hicpp, performance
  • Loading branch information
THETCR committed Aug 18, 2019
2 parents 771d21b + 538e00e commit e1db6e4
Show file tree
Hide file tree
Showing 238 changed files with 1,491 additions and 1,426 deletions.
4 changes: 2 additions & 2 deletions src/activemasternode.cpp
Expand Up @@ -235,7 +235,7 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage)
}
}

bool CActiveMasternode::CreateBroadcast(std::string strService, std::string strKeyMasternode, std::string strTxHash, std::string strOutputIndex, std::string& errorMessage, CMasternodeBroadcast &mnb, bool fOffline)
bool CActiveMasternode::CreateBroadcast(const std::string& strService, const std::string& strKeyMasternode, const std::string& strTxHash, const std::string& strOutputIndex, std::string& errorMessage, CMasternodeBroadcast &mnb, bool fOffline)
{
CTxIn vin;
CPubKey pubKeyCollateralAddress;
Expand Down Expand Up @@ -341,7 +341,7 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr
return GetMasterNodeVin(vin, pubkey, secretKey, "", "");
}

bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex)
bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, const std::string& strTxHash, const std::string& strOutputIndex)
{
// wait for reindex and/or import to finish
if (fImporting || fReindex) return false;
Expand Down
4 changes: 2 additions & 2 deletions src/activemasternode.h
Expand Up @@ -34,7 +34,7 @@ class CActiveMasternode
bool CreateBroadcast(CTxIn vin, CService service, CKey key, CPubKey pubKey, CKey keyMasternode, CPubKey pubKeyMasternode, std::string& errorMessage, CMasternodeBroadcast &mnb);

/// Get 10000 WSP input that can be used for the Masternode
bool GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex);
bool GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey, const std::string& strTxHash, const std::string& strOutputIndex);
bool GetVinFromOutput(COutput out, CTxIn& vin, CPubKey& pubkey, CKey& secretKey);

public:
Expand All @@ -59,7 +59,7 @@ class CActiveMasternode
std::string GetStatus();

/// Create Masternode broadcast, needs to be relayed manually after that
bool CreateBroadcast(std::string strService, std::string strKey, std::string strTxHash, std::string strOutputIndex, std::string& errorMessage, CMasternodeBroadcast &mnb, bool fOffline = false);
bool CreateBroadcast(const std::string& strService, const std::string& strKey, const std::string& strTxHash, const std::string& strOutputIndex, std::string& errorMessage, CMasternodeBroadcast &mnb, bool fOffline = false);

/// Get 10000 WSP input that can be used for the Masternode
bool GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secretKey);
Expand Down
10 changes: 5 additions & 5 deletions src/addrman.cpp
Expand Up @@ -76,12 +76,12 @@ double CAddrInfo::GetChance(int64_t nNow) const

CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
{
std::map<CNetAddr, int>::iterator it = mapAddr.find(addr);
auto it = mapAddr.find(addr);
if (it == mapAddr.end())
return nullptr;
if (pnId)
*pnId = (*it).second;
std::map<int, CAddrInfo>::iterator it2 = mapInfo.find((*it).second);
auto it2 = mapInfo.find((*it).second);
if (it2 != mapInfo.end())
return &(*it2).second;
return nullptr;
Expand Down Expand Up @@ -335,7 +335,7 @@ void CAddrMan::Attempt_(const CService& addr, int64_t nTime)
CAddrInfo CAddrMan::Select_(bool newOnly)
{
if (size() == 0)
return CAddrInfo();
return {};

if (newOnly && nNew == 0)
return CAddrInfo();
Expand All @@ -344,7 +344,7 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
if (!newOnly && (nTried > 0 && (nNew == 0 || RandomInt(2) == 0))) {
// use a tried node
double fChanceFactor = 1.0;
while (1) {
while (true) {
int nKBucket = RandomInt(ADDRMAN_TRIED_BUCKET_COUNT);
int nKBucketPos = RandomInt(ADDRMAN_BUCKET_SIZE);
while (vvTried[nKBucket][nKBucketPos] == -1) {
Expand All @@ -361,7 +361,7 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
} else {
// use a new node
double fChanceFactor = 1.0;
while (1) {
while (true) {
int nUBucket = RandomInt(ADDRMAN_NEW_BUCKET_COUNT);
int nUBucketPos = RandomInt(ADDRMAN_BUCKET_SIZE);
while (vvNew[nUBucket][nUBucketPos] == -1) {
Expand Down
40 changes: 20 additions & 20 deletions src/addrman.h
Expand Up @@ -16,7 +16,7 @@

#include <map>
#include <set>
#include <stdint.h>
#include <cstdint>
#include <vector>

/**
Expand Down Expand Up @@ -295,34 +295,34 @@ class CAddrMan
s << nUBuckets;
std::map<int, int> mapUnkIds;
int nIds = 0;
for (std::map<int, CAddrInfo>::const_iterator it = mapInfo.begin(); it != mapInfo.end(); it++) {
mapUnkIds[(*it).first] = nIds;
const CAddrInfo& info = (*it).second;
for (const auto & it : mapInfo) {
mapUnkIds[it.first] = nIds;
const CAddrInfo& info = it.second;
if (info.nRefCount) {
assert(nIds != nNew); // this means nNew was wrong, oh ow
s << info;
nIds++;
}
}
nIds = 0;
for (std::map<int, CAddrInfo>::const_iterator it = mapInfo.begin(); it != mapInfo.end(); it++) {
const CAddrInfo& info = (*it).second;
for (const auto & it : mapInfo) {
const CAddrInfo& info = it.second;
if (info.fInTried) {
assert(nIds != nTried); // this means nTried was wrong, oh ow
s << info;
nIds++;
}
}
for (int bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
for (const auto & bucket : vvNew) {
int nSize = 0;
for (int i = 0; i < ADDRMAN_BUCKET_SIZE; i++) {
if (vvNew[bucket][i] != -1)
for (int i : bucket) {
if (i != -1)
nSize++;
}
s << nSize;
for (int i = 0; i < ADDRMAN_BUCKET_SIZE; i++) {
if (vvNew[bucket][i] != -1) {
int nIndex = mapUnkIds[vvNew[bucket][i]];
for (int i : bucket) {
if (i != -1) {
int nIndex = mapUnkIds[i];
s << nIndex;
}
}
Expand Down Expand Up @@ -436,14 +436,14 @@ class CAddrMan
{
std::vector<int>().swap(vRandom);
nKey = GetRandHash();
for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
vvNew[bucket][entry] = -1;
for (auto & bucket : vvNew) {
for (int & entry : bucket) {
entry = -1;
}
}
for (size_t bucket = 0; bucket < ADDRMAN_TRIED_BUCKET_COUNT; bucket++) {
for (size_t entry = 0; entry < ADDRMAN_BUCKET_SIZE; entry++) {
vvTried[bucket][entry] = -1;
for (auto & bucket : vvTried) {
for (int & entry : bucket) {
entry = -1;
}
}

Expand Down Expand Up @@ -503,8 +503,8 @@ class CAddrMan
{
LOCK(cs);
Check();
for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++)
nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0;
for (const auto & it : vAddr)
nAdd += Add_(it, source, nTimePenalty) ? 1 : 0;
Check();
}
if (nAdd)
Expand Down
10 changes: 5 additions & 5 deletions src/alert.cpp
Expand Up @@ -16,7 +16,7 @@

#include <algorithm>
#include <map>
#include <stdint.h>
#include <cstdint>

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
Expand Down Expand Up @@ -50,7 +50,7 @@ std::string CUnsignedAlert::ToString() const
for (auto& n: setCancel)
strSetCancel += strprintf("%d ", n);
std::string strSetSubVer;
for (std::string str : setSubVer)
for (const std::string& str : setSubVer)
strSetSubVer += "\"" + str + "\" ";
return strprintf(
"CAlert(\n"
Expand Down Expand Up @@ -110,7 +110,7 @@ bool CAlert::Cancels(const CAlert& alert) const
return (alert.nID <= nCancel || setCancel.count(alert.nID));
}

bool CAlert::AppliesTo(int nVersion, std::string strSubVerIn) const
bool CAlert::AppliesTo(int nVersion, const std::string& strSubVerIn) const
{
// TODO: rework for client-version-embedded-in-strSubVer ?
return (IsInEffect() &&
Expand Down Expand Up @@ -159,7 +159,7 @@ CAlert CAlert::getAlertByHash(const uint256& hash)
CAlert retval;
{
LOCK(cs_mapAlerts);
std::map<uint256, CAlert>::iterator mi = mapAlerts.find(hash);
auto mi = mapAlerts.find(hash);
if (mi != mapAlerts.end())
retval = mi->second;
}
Expand Down Expand Up @@ -196,7 +196,7 @@ bool CAlert::ProcessAlert(bool fThread)
{
LOCK(cs_mapAlerts);
// Cancel previous alerts
for (std::map<uint256, CAlert>::iterator mi = mapAlerts.begin(); mi != mapAlerts.end();) {
for (auto mi = mapAlerts.begin(); mi != mapAlerts.end();) {
const CAlert& alert = (*mi).second;
if (Cancels(alert)) {
LogPrint("alert", "cancelling alert %d\n", alert.nID);
Expand Down
2 changes: 1 addition & 1 deletion src/alert.h
Expand Up @@ -100,7 +100,7 @@ class CAlert : public CUnsignedAlert
uint256 GetHash() const;
bool IsInEffect() const;
bool Cancels(const CAlert& alert) const;
bool AppliesTo(int nVersion, std::string strSubVerIn) const;
bool AppliesTo(int nVersion, const std::string& strSubVerIn) const;
bool AppliesToMe() const;
bool RelayTo(CNode* pnode) const;
bool CheckSignature() const;
Expand Down
13 changes: 6 additions & 7 deletions src/allocators.h
Expand Up @@ -9,7 +9,7 @@
#include "support/cleanse.h"

#include <map>
#include <string.h>
#include <cstring>
#include <string>
#include <vector>

Expand Down Expand Up @@ -39,8 +39,7 @@ class LockedPageManagerBase
}

~LockedPageManagerBase()
{
}
= default;


// For all pages in affected range, increase lock count
Expand Down Expand Up @@ -201,7 +200,7 @@ struct secure_allocator : public std::allocator<T> {
~secure_allocator() throw() {}
template <typename _Other>
struct rebind {
typedef secure_allocator<_Other> other;
using other = secure_allocator<_Other>;
};

T* allocate(std::size_t n, const void* hint = nullptr)
Expand Down Expand Up @@ -247,7 +246,7 @@ struct zero_after_free_allocator : public std::allocator<T> {
~zero_after_free_allocator() throw() {}
template <typename _Other>
struct rebind {
typedef zero_after_free_allocator<_Other> other;
using other = zero_after_free_allocator<_Other>;
};

void deallocate(T* p, std::size_t n)
Expand All @@ -259,9 +258,9 @@ struct zero_after_free_allocator : public std::allocator<T> {
};

// This is exactly like std::string, but with a custom allocator.
typedef std::basic_string<char, std::char_traits<char>, secure_allocator<char> > SecureString;
using SecureString = std::basic_string<char, std::char_traits<char>, secure_allocator<char> >;

// Byte-vector that clears its contents before deletion.
typedef std::vector<char, zero_after_free_allocator<char> > CSerializeData;
using CSerializeData = std::vector<char, zero_after_free_allocator<char> >;

#endif // BITCOIN_ALLOCATORS_H
6 changes: 3 additions & 3 deletions src/amount.h
Expand Up @@ -12,7 +12,7 @@
#include <cstdlib>
#include <string>

typedef int64_t CAmount;
using CAmount = int64_t;

static const CAmount COIN = 100000000;
static const CAmount CENT = 1000000;
Expand All @@ -23,9 +23,9 @@ static const CAmount CENT = 1000000;
class CFeeRate
{
private:
CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
CAmount nSatoshisPerK{0}; // unit is satoshis-per-1,000-bytes
public:
CFeeRate() : nSatoshisPerK(0) {}
CFeeRate() = default;
explicit CFeeRate(const CAmount& _nSatoshisPerK) : nSatoshisPerK(_nSatoshisPerK) {}
CFeeRate(const CAmount& nFeePaid, size_t nSize);
CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
Expand Down
18 changes: 9 additions & 9 deletions src/base58.cpp
Expand Up @@ -8,12 +8,12 @@
#include "hash.h"
#include "uint256.h"

#include <assert.h>
#include <cassert>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <sstream>
#include <stdint.h>
#include <string.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <vector>

Expand Down Expand Up @@ -41,7 +41,7 @@ bool DecodeBase58(const char* psz, std::vector<unsigned char>& vch)
return false;
// Apply "b256 = b256 * 58 + ch".
int carry = ch - pszBase58;
for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); it != b256.rend(); it++) {
for (auto it = b256.rbegin(); it != b256.rend(); it++) {
carry += 58 * (*it);
*it = carry % 256;
carry /= 256;
Expand All @@ -55,7 +55,7 @@ bool DecodeBase58(const char* psz, std::vector<unsigned char>& vch)
if (*psz != 0)
return false;
// Skip leading zeroes in b256.
std::vector<unsigned char>::iterator it = b256.begin();
auto it = b256.begin();
while (it != b256.end() && *it == 0)
it++;
// Copy result into output vector.
Expand All @@ -73,8 +73,8 @@ std::string DecodeBase58(const char* psz)
std::stringstream ss;
ss << std::hex;

for (unsigned int i = 0; i < vch.size(); i++) {
unsigned char* c = &vch[i];
for (unsigned char & i : vch) {
unsigned char* c = &i;
ss << std::setw(2) << std::setfill('0') << (int)c[0];
}

Expand All @@ -95,7 +95,7 @@ std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
while (pbegin != pend) {
int carry = *pbegin;
// Apply "b58 = b58 * 256 + ch".
for (std::vector<unsigned char>::reverse_iterator it = b58.rbegin(); it != b58.rend(); it++) {
for (auto it = b58.rbegin(); it != b58.rend(); it++) {
carry += 256 * (*it);
*it = carry % 58;
carry /= 58;
Expand All @@ -104,7 +104,7 @@ std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
pbegin++;
}
// Skip leading zeroes in base58 result.
std::vector<unsigned char>::iterator it = b58.begin();
auto it = b58.begin();
while (it != b58.end() && *it == 0)
it++;
// Translate the result into a string.
Expand Down
4 changes: 2 additions & 2 deletions src/base58.h
Expand Up @@ -116,7 +116,7 @@ class CBitcoinAddress : public CBase58Data
bool IsValid() const;
bool IsValid(const CChainParams& params) const;

CBitcoinAddress() {}
CBitcoinAddress() = default;
CBitcoinAddress(const CTxDestination& dest) { Set(dest); }
CBitcoinAddress(const std::string& strAddress) { SetString(strAddress); }
CBitcoinAddress(const char* pszAddress) { SetString(pszAddress); }
Expand All @@ -139,7 +139,7 @@ class CBitcoinSecret : public CBase58Data
bool SetString(const std::string& strSecret);

CBitcoinSecret(const CKey& vchSecret) { SetKey(vchSecret); }
CBitcoinSecret() {}
CBitcoinSecret() = default;
};

template <typename K, int Size, CChainParams::Base58Type Type>
Expand Down

0 comments on commit e1db6e4

Please sign in to comment.