Skip to content

Commit 21685b3

Browse files
committed
refs #14599 - small Timer cleanup
1 parent 5f61b72 commit 21685b3

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

lib/timer.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ void TimerResults::reset()
8787

8888
Timer::Timer(std::string str, ShowTime showtimeMode, TimerResultsIntf* timerResults)
8989
: mName(std::move(str))
90-
, mMode(showtimeMode)
91-
, mStart(Clock::now())
9290
, mResults(timerResults)
93-
{}
91+
{
92+
if (showtimeMode == ShowTime::NONE)
93+
return;
94+
if (!mResults)
95+
return;
96+
mStart = Clock::now();
97+
}
9498

9599
Timer::~Timer()
96100
{
@@ -99,18 +103,13 @@ Timer::~Timer()
99103

100104
void Timer::stop()
101105
{
102-
if (mMode == ShowTime::NONE)
106+
if (mStart == TimePoint{})
103107
return;
104-
if (mStart != TimePoint{}) {
105-
if (!mResults) {
106-
assert(false);
107-
}
108-
else {
109-
auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - mStart);
110-
mResults->addResults(mName, diff);
111-
}
112-
}
113-
mMode = ShowTime::NONE; // prevent multiple stops
108+
109+
const auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - mStart);
110+
mResults->addResults(mName, diff);
111+
112+
mStart = TimePoint{}; // prevent multiple stops
114113
}
115114

116115
static std::string durationToString(std::chrono::milliseconds duration)

lib/timer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class CPPCHECKLIB Timer {
9797

9898
private:
9999
const std::string mName;
100-
ShowTime mMode{};
101100
TimePoint mStart;
102101
TimerResultsIntf* mResults{};
103102
};

0 commit comments

Comments
 (0)