File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,10 +87,14 @@ void TimerResults::reset()
8787
8888Timer::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
9599Timer::~Timer ()
96100{
@@ -99,18 +103,13 @@ Timer::~Timer()
99103
100104void 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
116115static 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