From 1c802244812ca1d67f55097b0e22b1eac95183c5 Mon Sep 17 00:00:00 2001 From: Maz Date: Fri, 4 Oct 2019 14:14:40 -0400 Subject: [PATCH] Actually cache the results of timespan_t::{zero,min,max}. --- engine/sc_timespan.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/engine/sc_timespan.hpp b/engine/sc_timespan.hpp index 7b4db5b7077..da1cd1fba58 100644 --- a/engine/sc_timespan.hpp +++ b/engine/sc_timespan.hpp @@ -250,18 +250,22 @@ namespace timespan_adl_barrier return timespan_t(t); } - static constexpr timespan_t zero() + static timespan_t zero() { - return timespan_t(); + static constexpr timespan_t cached_zero = timespan_t(); + return cached_zero; } - static constexpr timespan_t max() + static timespan_t max() { - return timespan_t(std::numeric_limits::max()); + static constexpr timespan_t cached_max = timespan_t( std::numeric_limits::max() ); + return cached_max; } - static constexpr timespan_t min() + static timespan_t min() { - return std::is_floating_point::value ? timespan_t(-std::numeric_limits::max()) : - timespan_t(std::numeric_limits::min()); + static constexpr timespan_t cached_min = std::is_floating_point::value + ? timespan_t( -std::numeric_limits::max() ) + : timespan_t( std::numeric_limits::min() ); + return cached_min; } };