File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919#include " timer.h"
2020
2121#include < algorithm>
22- #include < cassert>
2322#include < cstddef>
2423#include < iostream>
2524#include < utility>
@@ -87,10 +86,14 @@ void TimerResults::reset()
8786
8887Timer::Timer (std::string str, ShowTime showtimeMode, TimerResultsIntf* timerResults)
8988 : mName(std::move(str))
90- , mMode(showtimeMode)
91- , mStart(Clock::now())
9289 , mResults(timerResults)
93- {}
90+ {
91+ if (showtimeMode == ShowTime::NONE)
92+ return ;
93+ if (!mResults )
94+ return ;
95+ mStart = Clock::now ();
96+ }
9497
9598Timer::~Timer ()
9699{
@@ -99,18 +102,13 @@ Timer::~Timer()
99102
100103void Timer::stop ()
101104{
102- if (mMode == ShowTime::NONE )
105+ if (mStart == TimePoint{} )
103106 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
107+
108+ const auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now () - mStart );
109+ mResults ->addResults (mName , diff);
110+
111+ mStart = TimePoint{}; // prevent multiple stops
114112}
115113
116114static std::string durationToString (std::chrono::milliseconds duration)
Original file line number Diff line number Diff line change @@ -97,7 +97,6 @@ class CPPCHECKLIB Timer {
9797
9898private:
9999 const std::string mName ;
100- ShowTime mMode {};
101100 TimePoint mStart ;
102101 TimerResultsIntf* mResults {};
103102};
You can’t perform that action at this time.
0 commit comments