Skip to content

Commit a963e4e

Browse files
committed
scripted-diff: Prefer static constexpr for literal-type constants
-BEGIN VERIFY SCRIPT- git grep -l 'static const ' -- 'src/' ':(exclude)src/secp256k1/' \ | xargs sed -i -E '/\b(MIN_TRANSACTION_OUTPUT_WEIGHT|MAX_OUTPUTS_PER_BLOCK|MAX_FILTER|g_rng_temp_path_init)\b/!s/\bstatic const (bool|int|unsigned|size_t|CAmount|u?int(8|16|32|64)_t|std::chrono::[a-z_]+) /static constexpr \1 /g' -END VERIFY SCRIPT-
1 parent 18c05d9 commit a963e4e

118 files changed

Lines changed: 297 additions & 297 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/base58.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using util::ContainsNoNUL;
1818

1919
/** All alphanumeric characters except for "0", "I", "O", and "l" */
2020
static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
21-
static const int8_t mapBase58[256] = {
21+
static constexpr int8_t mapBase58[256] = {
2222
-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
2323
-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
2424
-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,

src/bench/chacha20.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include <vector>
1616

1717
/* Number of bytes to process per iteration */
18-
static const uint64_t BUFFER_SIZE_TINY = 64;
19-
static const uint64_t BUFFER_SIZE_SMALL = 256;
20-
static const uint64_t BUFFER_SIZE_LARGE{1_MiB};
18+
static constexpr uint64_t BUFFER_SIZE_TINY = 64;
19+
static constexpr uint64_t BUFFER_SIZE_SMALL = 256;
20+
static constexpr uint64_t BUFFER_SIZE_LARGE{1_MiB};
2121

2222
static void CHACHA20(benchmark::Bench& bench, size_t buffersize)
2323
{

src/bench/checkqueue.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#include <utility>
1717
#include <vector>
1818

19-
static const size_t BATCHES = 101;
20-
static const size_t BATCH_SIZE = 30;
21-
static const unsigned int QUEUE_BATCH_SIZE = 128;
19+
static constexpr size_t BATCHES = 101;
20+
static constexpr size_t BATCH_SIZE = 30;
21+
static constexpr unsigned int QUEUE_BATCH_SIZE = 128;
2222

2323
// This Benchmark tests the CheckQueue with a slightly realistic workload,
2424
// where checks all contain a prevector that is indirect 50% of the time

src/bench/crypto_hash.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <vector>
2121

2222
/* Number of bytes to hash per iteration */
23-
static const uint64_t BUFFER_SIZE = 1000*1000;
23+
static constexpr uint64_t BUFFER_SIZE = 1000*1000;
2424

2525
static void BenchRIPEMD160(benchmark::Bench& bench)
2626
{

src/bitcoin-cli.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ const TranslateFn G_TRANSLATION_FUN{nullptr};
6262

6363
static const char DEFAULT_RPCCONNECT[] = "127.0.0.1";
6464
static constexpr const char* DEFAULT_RPC_REQ_ID{"1"};
65-
static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
65+
static constexpr int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
6666
static constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0;
67-
static const bool DEFAULT_NAMED=false;
68-
static const int CONTINUE_EXECUTION=-1;
67+
static constexpr bool DEFAULT_NAMED=false;
68+
static constexpr int CONTINUE_EXECUTION=-1;
6969
static constexpr uint8_t NETINFO_MAX_LEVEL{4};
7070
static constexpr int8_t UNKNOWN_NETWORK{-1};
7171
// See GetNetworkName() in netbase.cpp

src/bitcoin-tx.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ using util::TrimStringView;
4040

4141
static bool fCreateBlank;
4242
static std::map<std::string,UniValue> registers;
43-
static const int CONTINUE_EXECUTION=-1;
43+
static constexpr int CONTINUE_EXECUTION=-1;
4444

4545
const TranslateFn G_TRANSLATION_FUN{nullptr};
4646

@@ -271,8 +271,8 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu
271271
throw std::runtime_error("invalid TX input txid");
272272
}
273273

274-
static const unsigned int minTxOutSz = 9;
275-
static const unsigned int maxVout = MAX_BLOCK_WEIGHT / (WITNESS_SCALE_FACTOR * minTxOutSz);
274+
static constexpr unsigned int minTxOutSz = 9;
275+
static constexpr unsigned int maxVout = MAX_BLOCK_WEIGHT / (WITNESS_SCALE_FACTOR * minTxOutSz);
276276

277277
// extract and validate vout
278278
const std::string& strVout = vStrInputParts[1];
@@ -524,7 +524,7 @@ static void MutateTxDelOutput(CMutableTransaction& tx, const std::string& strOut
524524
tx.vout.erase(tx.vout.begin() + *idx);
525525
}
526526

527-
static const unsigned int N_SIGHASH_OPTS = 7;
527+
static constexpr unsigned int N_SIGHASH_OPTS = 7;
528528
static const struct {
529529
const char *flagStr;
530530
int flags;

src/bitcoin-util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <memory>
2626
#include <thread>
2727

28-
static const int CONTINUE_EXECUTION=-1;
28+
static constexpr int CONTINUE_EXECUTION=-1;
2929

3030
const TranslateFn G_TRANSLATION_FUN{nullptr};
3131

src/chainparamsseeds.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* Each line contains a BIP155 serialized (networkID, addr, port) tuple.
1212
*/
13-
static const uint8_t chainparams_seed_main[] = {
13+
static constexpr uint8_t chainparams_seed_main[] = {
1414
0x06,0x10,0xfc,0x11,0xf7,0x69,0x16,0xe6,0x36,0x11,0x58,0xae,0x1d,0x4a,0xfc,0xf7,0x57,0xa4,0x20,0x8d,
1515
0x06,0x10,0xfc,0x17,0x43,0x69,0x54,0x14,0x4b,0x1f,0x56,0x89,0xd3,0xed,0x40,0x39,0x33,0x5c,0x20,0x8d,
1616
0x06,0x10,0xfc,0x1f,0x22,0xc3,0x95,0xdc,0xa3,0xaf,0x4a,0x93,0x82,0x51,0xbe,0xb9,0x18,0x58,0x20,0x8d,
@@ -2072,7 +2072,7 @@ static const uint8_t chainparams_seed_main[] = {
20722072
0x04,0x20,0xce,0x07,0x95,0xf3,0xa5,0xc1,0x90,0xc4,0x50,0xd5,0x22,0x86,0xa7,0x26,0x37,0x08,0xa2,0x31,0x1e,0x0d,0x77,0x48,0x0d,0x46,0xe0,0xfb,0x3d,0x71,0x60,0xe7,0x1d,0xce,0x20,0x8d,
20732073
};
20742074

2075-
static const uint8_t chainparams_seed_signet[] = {
2075+
static constexpr uint8_t chainparams_seed_signet[] = {
20762076
0x06,0x10,0xfc,0x1f,0x22,0xc3,0x95,0xdc,0xa3,0xaf,0x4a,0x93,0x82,0x51,0xbe,0xb9,0x18,0x58,0x95,0xbd,
20772077
0x05,0x20,0xd7,0x4d,0xd9,0xc4,0x7c,0x80,0x24,0x1d,0x48,0x2f,0x52,0xba,0x2a,0xaf,0x5d,0xf2,0xfc,0x04,0x58,0x56,0x4a,0x61,0x0f,0xde,0x4e,0xd8,0x13,0x55,0x98,0x55,0x53,0xc1,0x00,0x00,
20782078
0x05,0x20,0xd8,0xaf,0x32,0x40,0x0d,0x25,0x72,0x91,0xf5,0x14,0x2a,0xa7,0x7b,0x9f,0x6b,0xe8,0x02,0x9f,0x16,0x5e,0xa0,0xe0,0x6d,0x85,0xcc,0x79,0xf2,0xe2,0xc1,0x2b,0xe0,0x20,0x00,0x00,
@@ -2245,7 +2245,7 @@ static const uint8_t chainparams_seed_signet[] = {
22452245
0x04,0x20,0xc9,0x95,0x5a,0xf7,0x9a,0x27,0x09,0x6a,0xa2,0x24,0x65,0xb7,0x07,0xf0,0x28,0xee,0x8b,0xa9,0x5e,0x7c,0x37,0x19,0x14,0xc4,0x36,0x73,0x42,0xd2,0x87,0xae,0xa2,0x47,0x95,0xbd,
22462246
};
22472247

2248-
static const uint8_t chainparams_seed_test[] = {
2248+
static constexpr uint8_t chainparams_seed_test[] = {
22492249
0x06,0x10,0xfc,0x1f,0x22,0xc3,0x95,0xdc,0xa3,0xaf,0x4a,0x93,0x82,0x51,0xbe,0xb9,0x18,0x58,0x47,0x9d,
22502250
0x05,0x20,0x39,0x06,0xc0,0x95,0x12,0xe1,0xf8,0x86,0xc2,0x36,0x76,0xa9,0x96,0x2a,0x9d,0xbd,0x3d,0x70,0x43,0xfc,0x99,0xbf,0x27,0x15,0xa4,0x9c,0x10,0xa1,0xd5,0xa3,0x9d,0x52,0x00,0x00,
22512251
0x05,0x20,0x40,0x81,0xae,0x55,0xb2,0x9d,0xd0,0xff,0x99,0x51,0xd8,0xbc,0x35,0xb2,0x06,0xb7,0x1c,0xf6,0x16,0x35,0xae,0xc6,0xf7,0xa4,0x72,0xf8,0x37,0x41,0x8e,0x91,0x7b,0x2e,0x00,0x00,
@@ -2429,7 +2429,7 @@ static const uint8_t chainparams_seed_test[] = {
24292429
0x04,0x20,0xcc,0x99,0x76,0x52,0x43,0xcc,0x45,0x0a,0x49,0x5d,0x3f,0xa5,0x82,0xc3,0xc0,0xdb,0xcf,0xe5,0xda,0xfb,0xb3,0xd0,0xb9,0xd1,0xbc,0x1b,0x15,0x19,0xed,0xe0,0xd1,0x5f,0x47,0x9d,
24302430
};
24312431

2432-
static const uint8_t chainparams_seed_testnet4[] = {
2432+
static constexpr uint8_t chainparams_seed_testnet4[] = {
24332433
0x06,0x10,0xfc,0x1f,0x22,0xc3,0x95,0xdc,0xa3,0xaf,0x4a,0x93,0x82,0x51,0xbe,0xb9,0x18,0x58,0xbc,0xcd,
24342434
0x05,0x20,0xd3,0xbc,0x25,0x95,0x63,0x7f,0x34,0x02,0x18,0x69,0x91,0x9a,0x79,0x57,0x10,0xc0,0xe0,0xf5,0xcd,0x84,0x56,0x95,0xec,0x43,0xa4,0x9d,0xba,0x1b,0xb3,0xea,0x34,0x60,0x00,0x00,
24352435
0x05,0x20,0xd8,0xee,0x64,0x35,0x6c,0x53,0xe7,0x40,0xb8,0xc3,0x15,0x60,0x5b,0x9c,0x66,0x3d,0xbb,0xd9,0x7c,0x99,0xcc,0x3a,0x3a,0xf6,0xcb,0xd5,0xd4,0x51,0x98,0x04,0x68,0xad,0x00,0x00,

src/clientversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <string>
2424
#include <vector>
2525

26-
static const int CLIENT_VERSION =
26+
static constexpr int CLIENT_VERSION =
2727
10000 * CLIENT_VERSION_MAJOR
2828
+ 100 * CLIENT_VERSION_MINOR
2929
+ 1 * CLIENT_VERSION_BUILD;

src/compressor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct ScriptCompression
5959
* transactions, in which case this value becomes dependent on version
6060
* and nHeight of the enclosing transaction.
6161
*/
62-
static const unsigned int nSpecialScripts = 6;
62+
static constexpr unsigned int nSpecialScripts = 6;
6363

6464
template<typename Stream>
6565
void Ser(Stream &s, const CScript& script) {

0 commit comments

Comments
 (0)