Skip to content

Commit

Permalink
[core] Make some constants constexpr
Browse files Browse the repository at this point in the history
This allows us to avoid generating symbols in libCore for these constants
keeping the same amount of open calls at ROOT startup time.
  • Loading branch information
vepadulano committed Jan 16, 2024
1 parent 05626ea commit 4504241
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion core/base/inc/TString.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ friend std::strong_ordering operator<=>(const TString &s1, const TString &s2) {
public:
enum EStripType { kLeading = 0x1, kTrailing = 0x2, kBoth = 0x3 };
enum ECaseCompare { kExact, kIgnoreCase };
static const Ssiz_t kNPOS = ::kNPOS;
static constexpr Ssiz_t kNPOS = ::kNPOS;

TString(); // Null string
explicit TString(Ssiz_t ic); // Suggested capacity
Expand Down
6 changes: 0 additions & 6 deletions core/base/src/TString.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ as a TString, construct a TString from it, eg:
#include "TVirtualMutex.h"
#include "ThreadLocalStorage.h"

// Definition of the TString static data member. Declaration (even with
// initialization) in the class body *is not* definition according to C++
// standard. The definition must be explicitly done in one TU for ODR use. See
// https://en.cppreference.com/w/cpp/language/definition
const Ssiz_t TString::kNPOS;

#if defined(R__WIN32)
#define strtoull _strtoui64
#endif
Expand Down
38 changes: 19 additions & 19 deletions core/foundation/inc/RtypesCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,31 @@ typedef float Size_t; //Attribute size (float)

//---- constants ---------------------------------------------------------------

const Bool_t kTRUE = true;
const Bool_t kFALSE = false;
constexpr Bool_t kTRUE = true;
constexpr Bool_t kFALSE = false;

const Int_t kMaxUChar = 256;
const Int_t kMaxChar = kMaxUChar >> 1;
const Int_t kMinChar = -kMaxChar - 1;
constexpr Int_t kMaxUChar = 256;
constexpr Int_t kMaxChar = kMaxUChar >> 1;
constexpr Int_t kMinChar = -kMaxChar - 1;

const Int_t kMaxUShort = 65534;
const Int_t kMaxShort = kMaxUShort >> 1;
const Int_t kMinShort = -kMaxShort - 1;
constexpr Int_t kMaxUShort = 65534;
constexpr Int_t kMaxShort = kMaxUShort >> 1;
constexpr Int_t kMinShort = -kMaxShort - 1;

const UInt_t kMaxUInt = UInt_t(~0);
const Int_t kMaxInt = Int_t(kMaxUInt >> 1);
const Int_t kMinInt = -kMaxInt - 1;
constexpr UInt_t kMaxUInt = UInt_t(~0);
constexpr Int_t kMaxInt = Int_t(kMaxUInt >> 1);
constexpr Int_t kMinInt = -kMaxInt - 1;

const ULong_t kMaxULong = ULong_t(~0);
const Long_t kMaxLong = Long_t(kMaxULong >> 1);
const Long_t kMinLong = -kMaxLong - 1;
constexpr ULong_t kMaxULong = ULong_t(~0);
constexpr Long_t kMaxLong = Long_t(kMaxULong >> 1);
constexpr Long_t kMinLong = -kMaxLong - 1;

const ULong64_t kMaxULong64 = ULong64_t(~0LL);
const Long64_t kMaxLong64 = Long64_t(kMaxULong64 >> 1);
const Long64_t kMinLong64 = -kMaxLong64 - 1;
constexpr ULong64_t kMaxULong64 = ULong64_t(~0LL);
constexpr Long64_t kMaxLong64 = Long64_t(kMaxULong64 >> 1);
constexpr Long64_t kMinLong64 = -kMaxLong64 - 1;

const ULong_t kBitsPerByte = 8;
const Ssiz_t kNPOS = ~(Ssiz_t)0;
constexpr ULong_t kBitsPerByte = 8;
constexpr Ssiz_t kNPOS = ~(Ssiz_t)0;

//---- debug global ------------------------------------------------------------

Expand Down

0 comments on commit 4504241

Please sign in to comment.