Skip to content

Commit f6cee6e

Browse files
committed
[core] Make some constants constexpr
This allows us to avoid generating symbols in libCore for these constants keeping the same amount of open calls at ROOT startup time.
1 parent 1eb0146 commit f6cee6e

3 files changed

Lines changed: 20 additions & 26 deletions

File tree

core/base/inc/TString.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ friend std::strong_ordering operator<=>(const TString &s1, const TString &s2) {
277277
public:
278278
enum EStripType { kLeading = 0x1, kTrailing = 0x2, kBoth = 0x3 };
279279
enum ECaseCompare { kExact, kIgnoreCase };
280-
static const Ssiz_t kNPOS = ::kNPOS;
280+
static constexpr Ssiz_t kNPOS = ::kNPOS;
281281

282282
TString(); // Null string
283283
explicit TString(Ssiz_t ic); // Suggested capacity

core/base/src/TString.cxx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ as a TString, construct a TString from it, eg:
5454
#include "TVirtualMutex.h"
5555
#include "ThreadLocalStorage.h"
5656

57-
// Definition of the TString static data member. Declaration (even with
58-
// initialization) in the class body *is not* definition according to C++
59-
// standard. The definition must be explicitly done in one TU for ODR use. See
60-
// https://en.cppreference.com/w/cpp/language/definition
61-
const Ssiz_t TString::kNPOS;
62-
6357
#if defined(R__WIN32)
6458
#define strtoull _strtoui64
6559
#endif

core/foundation/inc/RtypesCore.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,31 +97,31 @@ typedef float Size_t; //Attribute size (float)
9797

9898
//---- constants ---------------------------------------------------------------
9999

100-
const Bool_t kTRUE = true;
101-
const Bool_t kFALSE = false;
100+
constexpr Bool_t kTRUE = true;
101+
constexpr Bool_t kFALSE = false;
102102

103-
const Int_t kMaxUChar = 256;
104-
const Int_t kMaxChar = kMaxUChar >> 1;
105-
const Int_t kMinChar = -kMaxChar - 1;
103+
constexpr Int_t kMaxUChar = 256;
104+
constexpr Int_t kMaxChar = kMaxUChar >> 1;
105+
constexpr Int_t kMinChar = -kMaxChar - 1;
106106

107-
const Int_t kMaxUShort = 65534;
108-
const Int_t kMaxShort = kMaxUShort >> 1;
109-
const Int_t kMinShort = -kMaxShort - 1;
107+
constexpr Int_t kMaxUShort = 65534;
108+
constexpr Int_t kMaxShort = kMaxUShort >> 1;
109+
constexpr Int_t kMinShort = -kMaxShort - 1;
110110

111-
const UInt_t kMaxUInt = UInt_t(~0);
112-
const Int_t kMaxInt = Int_t(kMaxUInt >> 1);
113-
const Int_t kMinInt = -kMaxInt - 1;
111+
constexpr UInt_t kMaxUInt = UInt_t(~0);
112+
constexpr Int_t kMaxInt = Int_t(kMaxUInt >> 1);
113+
constexpr Int_t kMinInt = -kMaxInt - 1;
114114

115-
const ULong_t kMaxULong = ULong_t(~0);
116-
const Long_t kMaxLong = Long_t(kMaxULong >> 1);
117-
const Long_t kMinLong = -kMaxLong - 1;
115+
constexpr ULong_t kMaxULong = ULong_t(~0);
116+
constexpr Long_t kMaxLong = Long_t(kMaxULong >> 1);
117+
constexpr Long_t kMinLong = -kMaxLong - 1;
118118

119-
const ULong64_t kMaxULong64 = ULong64_t(~0LL);
120-
const Long64_t kMaxLong64 = Long64_t(kMaxULong64 >> 1);
121-
const Long64_t kMinLong64 = -kMaxLong64 - 1;
119+
constexpr ULong64_t kMaxULong64 = ULong64_t(~0LL);
120+
constexpr Long64_t kMaxLong64 = Long64_t(kMaxULong64 >> 1);
121+
constexpr Long64_t kMinLong64 = -kMaxLong64 - 1;
122122

123-
const ULong_t kBitsPerByte = 8;
124-
const Ssiz_t kNPOS = ~(Ssiz_t)0;
123+
constexpr ULong_t kBitsPerByte = 8;
124+
constexpr Ssiz_t kNPOS = ~(Ssiz_t)0;
125125

126126
//---- debug global ------------------------------------------------------------
127127

0 commit comments

Comments
 (0)