Skip to content

Commit 73f4119

Browse files
committed
Refactoring: Removed using namespace <xxx> from bench/ and test/ source files.
1 parent 53442af commit 73f4119

22 files changed

+245
-290
lines changed

src/bench/bench.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,37 @@
99
#include <iomanip>
1010
#include <sys/time.h>
1111

12-
using namespace benchmark;
13-
14-
std::map<std::string, BenchFunction> BenchRunner::benchmarks;
12+
std::map<std::string, benchmark::BenchFunction> benchmark::BenchRunner::benchmarks;
1513

1614
static double gettimedouble(void) {
1715
struct timeval tv;
1816
gettimeofday(&tv, NULL);
1917
return tv.tv_usec * 0.000001 + tv.tv_sec;
2018
}
2119

22-
BenchRunner::BenchRunner(std::string name, BenchFunction func)
20+
benchmark::BenchRunner::BenchRunner(std::string name, benchmark::BenchFunction func)
2321
{
2422
benchmarks.insert(std::make_pair(name, func));
2523
}
2624

2725
void
28-
BenchRunner::RunAll(double elapsedTimeForOne)
26+
benchmark::BenchRunner::RunAll(double elapsedTimeForOne)
2927
{
3028
perf_init();
3129
std::cout << "#Benchmark" << "," << "count" << "," << "min" << "," << "max" << "," << "average" << ","
3230
<< "min_cycles" << "," << "max_cycles" << "," << "average_cycles" << "\n";
3331

34-
for (std::map<std::string,BenchFunction>::iterator it = benchmarks.begin();
32+
for (std::map<std::string,benchmark::BenchFunction>::iterator it = benchmarks.begin();
3533
it != benchmarks.end(); ++it) {
3634

3735
State state(it->first, elapsedTimeForOne);
38-
BenchFunction& func = it->second;
36+
benchmark::BenchFunction& func = it->second;
3937
func(state);
4038
}
4139
perf_fini();
4240
}
4341

44-
bool State::KeepRunning()
42+
bool benchmark::State::KeepRunning()
4543
{
4644
if (count & countMask) {
4745
++count;

src/bench/coin_selection.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
#include <boost/foreach.hpp>
99
#include <set>
1010

11-
using namespace std;
12-
13-
static void addCoin(const CAmount& nValue, const CWallet& wallet, vector<COutput>& vCoins)
11+
static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<COutput>& vCoins)
1412
{
1513
int nInput = 0;
1614

@@ -36,7 +34,7 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, vector<COutput
3634
static void CoinSelection(benchmark::State& state)
3735
{
3836
const CWallet wallet;
39-
vector<COutput> vCoins;
37+
std::vector<COutput> vCoins;
4038
LOCK(wallet.cs_wallet);
4139

4240
while (state.KeepRunning()) {
@@ -50,7 +48,7 @@ static void CoinSelection(benchmark::State& state)
5048
addCoin(1000 * COIN, wallet, vCoins);
5149
addCoin(3 * COIN, wallet, vCoins);
5250

53-
set<pair<const CWalletTx*, unsigned int> > setCoinsRet;
51+
std::set<std::pair<const CWalletTx*, unsigned int> > setCoinsRet;
5452
CAmount nValueRet;
5553
bool success = wallet.SelectCoinsMinConf(1003 * COIN, 1, 6, 0, vCoins, setCoinsRet, nValueRet);
5654
assert(success);

src/test/addrman_tests.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include "netbase.h"
1111
#include "random.h"
1212

13-
using namespace std;
14-
1513
class CAddrManTest : public CAddrMan
1614
{
1715
uint64_t state;
@@ -365,7 +363,7 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr)
365363
// Test 22: Sanity check, GetAddr should never return anything if addrman
366364
// is empty.
367365
BOOST_CHECK(addrman.size() == 0);
368-
vector<CAddress> vAddr1 = addrman.GetAddr();
366+
std::vector<CAddress> vAddr1 = addrman.GetAddr();
369367
BOOST_CHECK(vAddr1.size() == 0);
370368

371369
CAddress addr1 = CAddress(ResolveService("250.250.2.1", 8333), NODE_NONE);
@@ -401,7 +399,7 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr)
401399
int octet1 = i % 256;
402400
int octet2 = (i / 256) % 256;
403401
int octet3 = (i / (256 * 2)) % 256;
404-
string strAddr = boost::to_string(octet1) + "." + boost::to_string(octet2) + "." + boost::to_string(octet3) + ".23";
402+
std::string strAddr = boost::to_string(octet1) + "." + boost::to_string(octet2) + "." + boost::to_string(octet3) + ".23";
405403
CAddress addr = CAddress(ResolveService(strAddr), NODE_NONE);
406404

407405
// Ensure that for all addrs in addrman, isTerrible == false.
@@ -410,7 +408,7 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr)
410408
if (i % 8 == 0)
411409
addrman.Good(addr);
412410
}
413-
vector<CAddress> vAddr = addrman.GetAddr();
411+
std::vector<CAddress> vAddr = addrman.GetAddr();
414412

415413
size_t percent23 = (addrman.size() * 23) / 100;
416414
BOOST_CHECK(vAddr.size() == percent23);
@@ -452,7 +450,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket)
452450
BOOST_CHECK(info1.GetKey() != info2.GetKey());
453451
BOOST_CHECK(info1.GetTriedBucket(nKey1) != info2.GetTriedBucket(nKey1));
454452

455-
set<int> buckets;
453+
std::set<int> buckets;
456454
for (int i = 0; i < 255; i++) {
457455
CAddrInfo infoi = CAddrInfo(
458456
CAddress(ResolveService("250.1.1." + boost::to_string(i)), NODE_NONE),
@@ -505,7 +503,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket)
505503
BOOST_CHECK(info1.GetKey() != info2.GetKey());
506504
BOOST_CHECK(info1.GetNewBucket(nKey1) == info2.GetNewBucket(nKey1));
507505

508-
set<int> buckets;
506+
std::set<int> buckets;
509507
for (int i = 0; i < 255; i++) {
510508
CAddrInfo infoi = CAddrInfo(
511509
CAddress(ResolveService("250.1.1." + boost::to_string(i)), NODE_NONE),

src/test/bloom_tests.cpp

+27-29
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <boost/test/unit_test.hpp>
2222
#include <boost/tuple/tuple.hpp>
2323

24-
using namespace std;
25-
2624
BOOST_FIXTURE_TEST_SUITE(bloom_tests, BasicTestingSetup)
2725

2826
BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize)
@@ -43,8 +41,8 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize)
4341
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
4442
stream << filter;
4543

46-
vector<unsigned char> vch = ParseHex("03614e9b050000000000000001");
47-
vector<char> expected(vch.size());
44+
std::vector<unsigned char> vch = ParseHex("03614e9b050000000000000001");
45+
std::vector<char> expected(vch.size());
4846

4947
for (unsigned int i = 0; i < vch.size(); i++)
5048
expected[i] = (char)vch[i];
@@ -75,8 +73,8 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize_with_tweak)
7573
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
7674
stream << filter;
7775

78-
vector<unsigned char> vch = ParseHex("03ce4299050000000100008001");
79-
vector<char> expected(vch.size());
76+
std::vector<unsigned char> vch = ParseHex("03ce4299050000000100008001");
77+
std::vector<char> expected(vch.size());
8078

8179
for (unsigned int i = 0; i < vch.size(); i++)
8280
expected[i] = (char)vch[i];
@@ -86,24 +84,24 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize_with_tweak)
8684

8785
BOOST_AUTO_TEST_CASE(bloom_create_insert_key)
8886
{
89-
string strSecret = string("5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C");
87+
std::string strSecret = std::string("5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C");
9088
CBitcoinSecret vchSecret;
9189
BOOST_CHECK(vchSecret.SetString(strSecret));
9290

9391
CKey key = vchSecret.GetKey();
9492
CPubKey pubkey = key.GetPubKey();
95-
vector<unsigned char> vchPubKey(pubkey.begin(), pubkey.end());
93+
std::vector<unsigned char> vchPubKey(pubkey.begin(), pubkey.end());
9694

9795
CBloomFilter filter(2, 0.001, 0, BLOOM_UPDATE_ALL);
9896
filter.insert(vchPubKey);
9997
uint160 hash = pubkey.GetID();
100-
filter.insert(vector<unsigned char>(hash.begin(), hash.end()));
98+
filter.insert(std::vector<unsigned char>(hash.begin(), hash.end()));
10199

102100
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
103101
stream << filter;
104102

105-
vector<unsigned char> vch = ParseHex("038fc16b080000000000000001");
106-
vector<char> expected(vch.size());
103+
std::vector<unsigned char> vch = ParseHex("038fc16b080000000000000001");
104+
std::vector<char> expected(vch.size());
107105

108106
for (unsigned int i = 0; i < vch.size(); i++)
109107
expected[i] = (char)vch[i];
@@ -119,7 +117,7 @@ BOOST_AUTO_TEST_CASE(bloom_match)
119117

120118
// and one which spends it (e2769b09e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436)
121119
unsigned char ch[] = {0x01, 0x00, 0x00, 0x00, 0x01, 0x6b, 0xff, 0x7f, 0xcd, 0x4f, 0x85, 0x65, 0xef, 0x40, 0x6d, 0xd5, 0xd6, 0x3d, 0x4f, 0xf9, 0x4f, 0x31, 0x8f, 0xe8, 0x20, 0x27, 0xfd, 0x4d, 0xc4, 0x51, 0xb0, 0x44, 0x74, 0x01, 0x9f, 0x74, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x49, 0x30, 0x46, 0x02, 0x21, 0x00, 0xda, 0x0d, 0xc6, 0xae, 0xce, 0xfe, 0x1e, 0x06, 0xef, 0xdf, 0x05, 0x77, 0x37, 0x57, 0xde, 0xb1, 0x68, 0x82, 0x09, 0x30, 0xe3, 0xb0, 0xd0, 0x3f, 0x46, 0xf5, 0xfc, 0xf1, 0x50, 0xbf, 0x99, 0x0c, 0x02, 0x21, 0x00, 0xd2, 0x5b, 0x5c, 0x87, 0x04, 0x00, 0x76, 0xe4, 0xf2, 0x53, 0xf8, 0x26, 0x2e, 0x76, 0x3e, 0x2d, 0xd5, 0x1e, 0x7f, 0xf0, 0xbe, 0x15, 0x77, 0x27, 0xc4, 0xbc, 0x42, 0x80, 0x7f, 0x17, 0xbd, 0x39, 0x01, 0x41, 0x04, 0xe6, 0xc2, 0x6e, 0xf6, 0x7d, 0xc6, 0x10, 0xd2, 0xcd, 0x19, 0x24, 0x84, 0x78, 0x9a, 0x6c, 0xf9, 0xae, 0xa9, 0x93, 0x0b, 0x94, 0x4b, 0x7e, 0x2d, 0xb5, 0x34, 0x2b, 0x9d, 0x9e, 0x5b, 0x9f, 0xf7, 0x9a, 0xff, 0x9a, 0x2e, 0xe1, 0x97, 0x8d, 0xd7, 0xfd, 0x01, 0xdf, 0xc5, 0x22, 0xee, 0x02, 0x28, 0x3d, 0x3b, 0x06, 0xa9, 0xd0, 0x3a, 0xcf, 0x80, 0x96, 0x96, 0x8d, 0x7d, 0xbb, 0x0f, 0x91, 0x78, 0xff, 0xff, 0xff, 0xff, 0x02, 0x8b, 0xa7, 0x94, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xba, 0xde, 0xec, 0xfd, 0xef, 0x05, 0x07, 0x24, 0x7f, 0xc8, 0xf7, 0x42, 0x41, 0xd7, 0x3b, 0xc0, 0x39, 0x97, 0x2d, 0x7b, 0x88, 0xac, 0x40, 0x94, 0xa8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xc1, 0x09, 0x32, 0x48, 0x3f, 0xec, 0x93, 0xed, 0x51, 0xf5, 0xfe, 0x95, 0xe7, 0x25, 0x59, 0xf2, 0xcc, 0x70, 0x43, 0xf9, 0x88, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00};
122-
vector<unsigned char> vch(ch, ch + sizeof(ch) -1);
120+
std::vector<unsigned char> vch(ch, ch + sizeof(ch) -1);
123121
CDataStream spendStream(vch, SER_DISK, CLIENT_VERSION);
124122
CTransaction spendingTx(deserialize, spendStream);
125123

@@ -156,7 +154,7 @@ BOOST_AUTO_TEST_CASE(bloom_match)
156154
filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL);
157155
COutPoint prevOutPoint(uint256S("0x90c122d70786e899529d71dbeba91ba216982fb6ba58f3bdaab65e73b7e9260b"), 0);
158156
{
159-
vector<unsigned char> data(32 + sizeof(unsigned int));
157+
std::vector<unsigned char> data(32 + sizeof(unsigned int));
160158
memcpy(&data[0], prevOutPoint.hash.begin(), 32);
161159
memcpy(&data[32], &prevOutPoint.n, sizeof(unsigned int));
162160
filter.insert(data);
@@ -196,13 +194,13 @@ BOOST_AUTO_TEST_CASE(merkle_block_1)
196194
BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
197195

198196
BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1);
199-
pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
197+
std::pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
200198

201199
BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256S("0x74d681e0e03bafa802c8aa084379aa98d9fcd632ddc2ed9782b586ec87451f20"));
202200
BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 8);
203201

204-
vector<uint256> vMatched;
205-
vector<unsigned int> vIndex;
202+
std::vector<uint256> vMatched;
203+
std::vector<unsigned int> vIndex;
206204
BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
207205
BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
208206
for (unsigned int i = 0; i < vMatched.size(); i++)
@@ -242,13 +240,13 @@ BOOST_AUTO_TEST_CASE(merkle_block_2)
242240
BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
243241

244242
BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1);
245-
pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
243+
std::pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
246244

247245
BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256S("0xe980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"));
248246
BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0);
249247

250-
vector<uint256> vMatched;
251-
vector<unsigned int> vIndex;
248+
std::vector<uint256> vMatched;
249+
std::vector<unsigned int> vIndex;
252250
BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
253251
BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
254252
for (unsigned int i = 0; i < vMatched.size(); i++)
@@ -297,13 +295,13 @@ BOOST_AUTO_TEST_CASE(merkle_block_2_with_update_none)
297295
BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
298296

299297
BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1);
300-
pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
298+
std::pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
301299

302300
BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256S("0xe980fe9f792d014e73b95203dc1335c5f9ce19ac537a419e6df5b47aecb93b70"));
303301
BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0);
304302

305-
vector<uint256> vMatched;
306-
vector<unsigned int> vIndex;
303+
std::vector<uint256> vMatched;
304+
std::vector<unsigned int> vIndex;
307305
BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
308306
BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
309307
for (unsigned int i = 0; i < vMatched.size(); i++)
@@ -353,8 +351,8 @@ BOOST_AUTO_TEST_CASE(merkle_block_3_and_serialize)
353351
BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256S("0x63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5"));
354352
BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 0);
355353

356-
vector<uint256> vMatched;
357-
vector<unsigned int> vIndex;
354+
std::vector<uint256> vMatched;
355+
std::vector<unsigned int> vIndex;
358356
BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
359357
BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
360358
for (unsigned int i = 0; i < vMatched.size(); i++)
@@ -363,8 +361,8 @@ BOOST_AUTO_TEST_CASE(merkle_block_3_and_serialize)
363361
CDataStream merkleStream(SER_NETWORK, PROTOCOL_VERSION);
364362
merkleStream << merkleBlock;
365363

366-
vector<unsigned char> vch = ParseHex("0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b4b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f196367291b4d4c86041b8fa45d630100000001b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f19630101");
367-
vector<char> expected(vch.size());
364+
std::vector<unsigned char> vch = ParseHex("0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b4b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f196367291b4d4c86041b8fa45d630100000001b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f19630101");
365+
std::vector<char> expected(vch.size());
368366

369367
for (unsigned int i = 0; i < vch.size(); i++)
370368
expected[i] = (char)vch[i];
@@ -388,13 +386,13 @@ BOOST_AUTO_TEST_CASE(merkle_block_4)
388386
BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash());
389387

390388
BOOST_CHECK(merkleBlock.vMatchedTxn.size() == 1);
391-
pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
389+
std::pair<unsigned int, uint256> pair = merkleBlock.vMatchedTxn[0];
392390

393391
BOOST_CHECK(merkleBlock.vMatchedTxn[0].second == uint256S("0x0a2a92f0bda4727d0a13eaddf4dd9ac6b5c61a1429e6b2b818f19b15df0ac154"));
394392
BOOST_CHECK(merkleBlock.vMatchedTxn[0].first == 6);
395393

396-
vector<uint256> vMatched;
397-
vector<unsigned int> vIndex;
394+
std::vector<uint256> vMatched;
395+
std::vector<unsigned int> vIndex;
398396
BOOST_CHECK(merkleBlock.txn.ExtractMatches(vMatched, vIndex) == block.hashMerkleRoot);
399397
BOOST_CHECK(vMatched.size() == merkleBlock.vMatchedTxn.size());
400398
for (unsigned int i = 0; i < vMatched.size(); i++)

0 commit comments

Comments
 (0)