From 98c7768fd068d08b1c045a2fda9a0c018882d0da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Tue, 6 May 2025 17:49:01 +0200 Subject: [PATCH] Add _int64_abs function --- server/TracyPrint.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/server/TracyPrint.cpp b/server/TracyPrint.cpp index f9daaf1a..d77c1375 100644 --- a/server/TracyPrint.cpp +++ b/server/TracyPrint.cpp @@ -71,7 +71,7 @@ static inline void PrintSmallInt( char*& buf, uint64_t v ) static inline void PrintSmallInt0( char*& buf, uint64_t v ) { - assert( v < 1000 ); + assert( v < uint64_t(1000ll) ); if( v >= 100 ) { memcpy( buf, IntTable100 + v/10*2, 2 ); @@ -155,6 +155,22 @@ static inline void PrintSecondsFrac( char*& buf, uint64_t v ) } } +uint64_t _int64_abs( int64_t x ) +{ + if( x == std::numeric_limits::min() ) + { + return -(x + 1) + 1; + } + else if( x < 0 ) + { + return -x; + } + else + { + return x; + } +} + const char* TimeToString( int64_t _ns ) { enum { Pool = 8 }; @@ -164,16 +180,11 @@ const char* TimeToString( int64_t _ns ) char* bufstart = buf; bufsel = ( bufsel + 1 ) % Pool; - uint64_t ns; + uint64_t ns = _int64_abs(_ns); if( _ns < 0 ) { *buf = '-'; buf++; - ns = -_ns; - } - else - { - ns = _ns; } if( ns < 1000 ) @@ -245,20 +256,11 @@ const char* TimeToStringExact( int64_t _ns ) char* bufstart = buf; bufsel = ( bufsel + 1 ) % Pool; - uint64_t ns; - if( _ns == std::numeric_limits::min() ) - { - ns = -(_ns + 1) + 1; - } - else if( _ns < 0 ) + uint64_t ns = _int64_abs(_ns); + if( _ns < 0 ) { *buf = '-'; buf++; - ns = -_ns; - } - else - { - ns = _ns; } const char* numStart = buf;