Skip to content

Commit a336cd7

Browse files
committed
[Math] Include <chrono> in Util.h to avoid hack with casting to void*
1 parent 85ae601 commit a336cd7

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

math/mathcore/inc/Math/Util.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef ROOT_Math_Util
1414
#define ROOT_Math_Util
1515

16+
#include <chrono>
1617
#include <cmath>
1718
#include <functional>
1819
#include <limits>
@@ -51,7 +52,7 @@ class TimingScope {
5152
~TimingScope();
5253

5354
private:
54-
void *fBegin;
55+
std::chrono::steady_clock::time_point fBegin;
5556
std::function<void(std::string const&)> fPrinter;
5657
const std::string fMessage;
5758
};

math/mathcore/src/Util.cxx

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#include "Math/Util.h"
22

3-
#include <chrono>
4-
53
ROOT::Math::Util::TimingScope::TimingScope(std::function<void(std::string const &)> printer, std::string const &message)
6-
: fPrinter{printer}, fMessage{message}
4+
: fBegin{std::chrono::steady_clock::now()}, fPrinter{printer}, fMessage{message}
75
{
8-
using std::chrono::steady_clock;
9-
fBegin = new steady_clock::time_point{steady_clock::now()};
106
}
117

128
namespace {
@@ -59,10 +55,8 @@ std::string printTime(T duration)
5955
ROOT::Math::Util::TimingScope::~TimingScope()
6056
{
6157
using std::chrono::steady_clock;
62-
auto *begin = reinterpret_cast<steady_clock::time_point *>(fBegin);
6358
steady_clock::time_point end = steady_clock::now();
6459
std::stringstream ss;
65-
ss << fMessage << " " << printTime(end - *begin);
60+
ss << fMessage << " " << printTime(end - fBegin);
6661
fPrinter(ss.str());
67-
delete begin;
6862
}

0 commit comments

Comments
 (0)