Skip to content

Commit 5e46187

Browse files
HaroldoCopilot
andcommitted
CoinTime: refactor CoinWallclockTime to C++17 inline variable
Replace the function-local static + callType overload with a C++17 inline const double coinWallclockStart initialised at static-init time (before main()). CoinWallclockTime() is now a simple subtraction with no branching or guard state. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4c7b035 commit 5e46187

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/CoinTime.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,15 @@ inline double CoinGetTimeOfDay()
8888

8989
#endif // _MSC_VER
9090

91-
/**
92-
Query the elapsed wallclock time since the first call to this function. If
93-
a positive argument is passed to the function then the time of the first
94-
call is set to that value (this kind of argument is allowed only at the
95-
first call!). If a negative argument is passed to the function then it
96-
returns the time when it was set.
97-
*/
91+
/// Wall-clock epoch seconds at static-initialisation time (before main()).
92+
/// Defined as an inline variable (C++17) so every translation unit shares
93+
/// the same object and the value is fixed exactly once.
94+
inline const double coinWallclockStart = CoinGetTimeOfDay();
9895

99-
inline double CoinWallclockTime(double callType = 0)
96+
/// Returns elapsed wall-clock time in seconds since program start.
97+
inline double CoinWallclockTime()
10098
{
101-
double callTime = CoinGetTimeOfDay();
102-
static const double firstCall = callType > 0 ? callType : callTime;
103-
return callType < 0 ? firstCall : callTime - firstCall;
99+
return CoinGetTimeOfDay() - coinWallclockStart;
104100
}
105101

106102
//#############################################################################

0 commit comments

Comments
 (0)