Browse Source

Merge #10749: Use compile-time constants instead of unnamed enumerations (remove "enum hack")

1e65f0f33 Use compile-time constants instead of unnamed enumerations (remove "enum hack") (practicalswift)

Pull request description:

  Use compile-time constants instead of unnamed enumerations (remove "enum hack").

Tree-SHA512: 1b6ebb2755398c5ebab6cce125b1dfc39cbd1504d98d55136b32703fe935c4070360ab3b2f52b1da48ba9f3b01082d204f3d87c92ccb5c8c333731f7f972e128
0.16
MarcoFalke 7 years ago
parent
commit
2adbddb038
No known key found for this signature in database
GPG Key ID: D2EA4850E7528B25
  1. 2
      src/arith_uint256.h
  2. 2
      src/chain.h
  3. 11
      src/consensus/consensus.h
  4. 17
      src/protocol.h
  5. 2
      src/uint256.h

2
src/arith_uint256.h

@ -25,7 +25,7 @@ template<unsigned int BITS>
class base_uint class base_uint
{ {
protected: protected:
enum { WIDTH=BITS/32 }; static constexpr int WIDTH = BITS / 32;
uint32_t pn[WIDTH]; uint32_t pn[WIDTH];
public: public:

2
src/chain.h

@ -304,7 +304,7 @@ public:
return (int64_t)nTimeMax; return (int64_t)nTimeMax;
} }
enum { nMedianTimeSpan=11 }; static constexpr int nMedianTimeSpan = 11;
int64_t GetMedianTimePast() const int64_t GetMedianTimePast() const
{ {

11
src/consensus/consensus.h

@ -24,12 +24,9 @@ static const size_t MIN_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 60; // 60 is
static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 10; // 10 is the lower bound for the size of a serialized CTransaction static const size_t MIN_SERIALIZABLE_TRANSACTION_WEIGHT = WITNESS_SCALE_FACTOR * 10; // 10 is the lower bound for the size of a serialized CTransaction
/** Flags for nSequence and nLockTime locks */ /** Flags for nSequence and nLockTime locks */
enum { /** Interpret sequence numbers as relative lock-time constraints. */
/* Interpret sequence numbers as relative lock-time constraints. */ static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE = (1 << 0);
LOCKTIME_VERIFY_SEQUENCE = (1 << 0), /** Use GetMedianTimePast() instead of nTime for end point timestamp. */
static constexpr unsigned int LOCKTIME_MEDIAN_TIME_PAST = (1 << 1);
/* Use GetMedianTimePast() instead of nTime for end point timestamp. */
LOCKTIME_MEDIAN_TIME_PAST = (1 << 1),
};
#endif // BITCOIN_CONSENSUS_CONSENSUS_H #endif // BITCOIN_CONSENSUS_CONSENSUS_H

17
src/protocol.h

@ -27,16 +27,13 @@
class CMessageHeader class CMessageHeader
{ {
public: public:
enum { static constexpr size_t MESSAGE_START_SIZE = 4;
MESSAGE_START_SIZE = 4, static constexpr size_t COMMAND_SIZE = 12;
COMMAND_SIZE = 12, static constexpr size_t MESSAGE_SIZE_SIZE = 4;
MESSAGE_SIZE_SIZE = 4, static constexpr size_t CHECKSUM_SIZE = 4;
CHECKSUM_SIZE = 4, static constexpr size_t MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE;
static constexpr size_t CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE;
MESSAGE_SIZE_OFFSET = MESSAGE_START_SIZE + COMMAND_SIZE, static constexpr size_t HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE;
CHECKSUM_OFFSET = MESSAGE_SIZE_OFFSET + MESSAGE_SIZE_SIZE,
HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE
};
typedef unsigned char MessageStartChars[MESSAGE_START_SIZE]; typedef unsigned char MessageStartChars[MESSAGE_START_SIZE];
explicit CMessageHeader(const MessageStartChars& pchMessageStartIn); explicit CMessageHeader(const MessageStartChars& pchMessageStartIn);

2
src/uint256.h

@ -19,7 +19,7 @@ template<unsigned int BITS>
class base_blob class base_blob
{ {
protected: protected:
enum { WIDTH=BITS/8 }; static constexpr int WIDTH = BITS / 8;
uint8_t data[WIDTH]; uint8_t data[WIDTH];
public: public:
base_blob() base_blob()

Loading…
Cancel
Save