Skip to content

Commit 9bd7729

Browse files
committed
Don't include TMathBase.h in TString.h
The TString header only uses `TMath` functions that are readily available in the standard library. The `TMathBase.h` header is quite big, and avoiding to include it reduces the overall cold-ccache compile time of the full ROOT project with all default features by about 2 % on my machine, namely from 870 s to 855 s on average. In the places where the `TMath` functions were used but only indirectly included via `TString.h` inclusion, the commit suggests to use the `<cmath>` functions instead.
1 parent 984363d commit 9bd7729

File tree

137 files changed

+535
-458
lines changed

Some content is hidden

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

137 files changed

+535
-458
lines changed

README/ReleaseNotes/v638/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ the deprecation period was extended.
9595
## JavaScript ROOT
9696
- A new configuration option `Jupyter.JSRoot` was added in .rootrc to set the default mode for JSROOT in Jupyter notebooks (on or off).
9797

98+
### Optimization of ROOT header files
99+
100+
More unused includes were removed from ROOT header files.
101+
For instance, `#include "TMathBase.h"` was removed from `TString.h`.
102+
This change may cause errors during compilation of ROOT-based code. To fix it, provide missing the includes
103+
where they are really required.
104+
This improves compile times and reduces code inter-dependency; see https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md for a good overview of the motivation.
98105

99106
## Versions of built-in packages
100107

core/base/inc/TString.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include "Rtypes.h"
2727

28-
#include "TMathBase.h"
2928
#include <string_view>
3029
#include "ROOT/TypeTraits.hxx"
3130
#include "snprintf.h"
@@ -579,7 +578,7 @@ inline TString &TString::Append(const TString &s)
579578
{ return Replace(Length(), 0, s.Data(), s.Length()); }
580579

581580
inline TString &TString::Append(const TString &s, Ssiz_t n)
582-
{ return Replace(Length(), 0, s.Data(), TMath::Min(n, s.Length())); }
581+
{ return Replace(Length(), 0, s.Data(), std::min(n, s.Length())); }
583582

584583
inline TString &TString::operator+=(const char *cs)
585584
{ return Append(cs, cs ? (Ssiz_t)strlen(cs) : 0); }
@@ -668,7 +667,7 @@ inline TString &TString::Insert(Ssiz_t pos, const TString &s)
668667
{ return Replace(pos, 0, s.Data(), s.Length()); }
669668

670669
inline TString &TString::Insert(Ssiz_t pos, const TString &s, Ssiz_t n)
671-
{ return Replace(pos, 0, s.Data(), TMath::Min(n, s.Length())); }
670+
{ return Replace(pos, 0, s.Data(), std::min(n, s.Length())); }
672671

673672
inline TString &TString::Prepend(const char *cs)
674673
{ return Replace(0, 0, cs, cs ? (Ssiz_t)strlen(cs) : 0); }
@@ -680,16 +679,16 @@ inline TString &TString::Prepend(const TString &s)
680679
{ return Replace(0, 0, s.Data(), s.Length()); }
681680

682681
inline TString &TString::Prepend(const TString &s, Ssiz_t n)
683-
{ return Replace(0, 0, s.Data(), TMath::Min(n, s.Length())); }
682+
{ return Replace(0, 0, s.Data(), std::min(n, s.Length())); }
684683

685684
inline TString &TString::Remove(Ssiz_t pos)
686-
{ return Replace(pos, TMath::Max(0, Length()-pos), nullptr, 0); }
685+
{ return Replace(pos, std::max(0, Length()-pos), nullptr, 0); }
687686

688687
inline TString &TString::Remove(Ssiz_t pos, Ssiz_t n)
689688
{ return Replace(pos, n, nullptr, 0); }
690689

691690
inline TString &TString::Chop()
692-
{ return Remove(TMath::Max(0, Length()-1)); }
691+
{ return Remove(std::max(0, Length()-1)); }
693692

694693
inline TString &TString::Replace(Ssiz_t pos, Ssiz_t n, const char *cs)
695694
{ return Replace(pos, n, cs, cs ? (Ssiz_t)strlen(cs) : 0); }
@@ -699,7 +698,7 @@ inline TString &TString::Replace(Ssiz_t pos, Ssiz_t n, const TString& s)
699698

700699
inline TString &TString::Replace(Ssiz_t pos, Ssiz_t n1, const TString &s,
701700
Ssiz_t n2)
702-
{ return Replace(pos, n1, s.Data(), TMath::Min(s.Length(), n2)); }
701+
{ return Replace(pos, n1, s.Data(), std::min(s.Length(), n2)); }
703702

704703
inline TString &TString::ReplaceAll(const TString &s1, const TString &s2)
705704
{ return ReplaceAll(s1.Data(), s1.Length(), s2.Data(), s2.Length()) ; }

core/base/inc/TStyle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class TStyle : public TNamed, public TAttLine, public TAttFill, public TAttMarke
305305
void SetFitFormat(const char *format="5.4g") {fFitFormat = format;}
306306
void SetHeaderPS(const char *header);
307307
void SetHatchesLineWidth(Int_t l) {fHatchesLineWidth = l;}
308-
void SetHatchesSpacing(Double_t h) {fHatchesSpacing = TMath::Max(0.1,h);}
308+
void SetHatchesSpacing(Double_t h) {fHatchesSpacing = std::max(0.1,h);}
309309
void SetTitlePS(const char *pstitle);
310310
void SetJoinLinePS(Int_t joinline=0) {fJoinLinePS=joinline;} ///< Set the line join method used for PostScript, PDF and SVG output. See `TPostScript::SetLineJoin` for details.
311311
void SetCapLinePS(Int_t capline=0) {fCapLinePS=capline;} ///< Set the line cap method used for PostScript, PDF and SVG output. See `TPostScript::SetLineCap` for details.

core/base/src/TAttLine.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ Int_t TAttLine::DistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, D
235235
if (c <= 0) return 9999;
236236
Double_t v = sqrt(c);
237237
Double_t u = (a - b + c)/(2*v);
238-
Double_t d = TMath::Abs(a - u*u);
238+
Double_t d = std::abs(a - u*u);
239239
if (d < 0) return 9999;
240240

241241
return Int_t(sqrt(d) - 0.5*Double_t(fLineWidth));
@@ -247,7 +247,7 @@ Int_t TAttLine::DistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, D
247247
void TAttLine::Modify()
248248
{
249249
if (!gPad) return;
250-
Int_t lineWidth = TMath::Abs(fLineWidth%100);
250+
Int_t lineWidth = std::abs(fLineWidth%100);
251251
if (!gPad->IsBatch()) {
252252
gVirtualX->SetLineColor(fLineColor);
253253
if (fLineStyle > 0 && fLineStyle < 30) gVirtualX->SetLineStyle(fLineStyle);

core/base/src/TAttText.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ Float_t TAttText::GetTextSizePercent(Float_t size)
312312
{
313313
Float_t rsize = size;
314314
if (fTextFont%10 > 2 && gPad) {
315-
UInt_t w = TMath::Abs(gPad->XtoAbsPixel(gPad->GetX2()) -
316-
gPad->XtoAbsPixel(gPad->GetX1()));
317-
UInt_t h = TMath::Abs(gPad->YtoAbsPixel(gPad->GetY2()) -
318-
gPad->YtoAbsPixel(gPad->GetY1()));
315+
UInt_t w = std::abs(gPad->XtoAbsPixel(gPad->GetX2()) -
316+
gPad->XtoAbsPixel(gPad->GetX1()));
317+
UInt_t h = std::abs(gPad->YtoAbsPixel(gPad->GetY2()) -
318+
gPad->YtoAbsPixel(gPad->GetY1()));
319319
if (w < h)
320320
rsize = rsize/w;
321321
else

core/base/src/TDirectory.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
#include "TSpinLockGuard.h"
3131

32+
#include <algorithm>
33+
#include <limits>
34+
3235
Bool_t TDirectory::fgAddDirectory = kTRUE;
3336

3437
const Int_t kMaxLen = 2048;

core/base/src/TObject.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class hierarchies (watch out for overlaps).
4747
#include <fstream>
4848
#include <iostream>
4949
#include <iomanip>
50+
#include <limits>
5051

5152
#include "Varargs.h"
5253
#include "snprintf.h"

core/base/src/TStorage.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void *ROOT::Internal::gMmallocDesc = nullptr; //is used and set in TMapFile
9898

9999
void TStorage::EnterStat(size_t size, void *p)
100100
{
101-
TStorage::SetMaxBlockSize(TMath::Max(TStorage::GetMaxBlockSize(), size));
101+
TStorage::SetMaxBlockSize(std::max(TStorage::GetMaxBlockSize(), size));
102102

103103
if (!gMemStatistics) return;
104104

core/base/src/TString.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ TString &TString::Replace(Ssiz_t pos, Ssiz_t n1, const char *cs, Ssiz_t n2)
10331033
return *this;
10341034
}
10351035

1036-
n1 = TMath::Min(n1, len - pos);
1036+
n1 = std::min(n1, len - pos);
10371037
if (!cs) n2 = 0;
10381038

10391039
Long64_t tot = static_cast<Long64_t>(len) - n1 + n2; // Final string length, use 64-bit long instead of 32-bit int to check for overflows
@@ -1225,7 +1225,7 @@ Ssiz_t TString::AdjustCapacity(Ssiz_t oldCap, Ssiz_t newCap)
12251225
newCap, ms);
12261226
}
12271227
Ssiz_t cap = oldCap < ms / 2 - kAlignment ?
1228-
Recommend(TMath::Max(newCap, 2 * oldCap)) : ms - 1;
1228+
Recommend(std::max(newCap, 2 * oldCap)) : ms - 1;
12291229
return cap;
12301230
}
12311231

@@ -2101,7 +2101,7 @@ TString TString::Itoa(Int_t value, Int_t base)
21012101
Int_t quotient = value;
21022102
// Translating number to string with base:
21032103
do {
2104-
buf += "0123456789abcdefghijklmnopqrstuvwxyz"[ TMath::Abs(quotient % base) ];
2104+
buf += "0123456789abcdefghijklmnopqrstuvwxyz"[ std::abs(quotient % base) ];
21052105
quotient /= base;
21062106
} while (quotient);
21072107
// Append the negative sign
@@ -2153,7 +2153,7 @@ TString TString::LLtoa(Long64_t value, Int_t base)
21532153
Long64_t quotient = value;
21542154
// Translating number to string with base:
21552155
do {
2156-
buf += "0123456789abcdefghijklmnopqrstuvwxyz"[ TMath::Abs(quotient % base) ];
2156+
buf += "0123456789abcdefghijklmnopqrstuvwxyz"[ std::abs(quotient % base) ];
21572157
quotient /= base;
21582158
} while (quotient);
21592159
// Append the negative sign

core/base/src/TTimeStamp.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ NOTE: the use of time_t (and its default implementation as a 32 int)
4949
#endif
5050
#include "TVirtualMutex.h"
5151

52+
#include <cmath>
53+
5254
ClassImp(TTimeStamp);
5355

5456

0 commit comments

Comments
 (0)