From 4a6bc284aff16fe8990d5baadbc55f997a6c5ddb Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 31 Jan 2020 18:26:00 +0100 Subject: [PATCH] Optimize "string (percentage)" printing. --- server/TracyView.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index da9e8a11..682ac557 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -6465,6 +6465,15 @@ void View::DrawZoneInfoWindow() } } +static tracy_force_inline void PrintStringPercent( char* buf, const char* string, double percent ) +{ + const auto ssz = strlen( string ); + memcpy( buf, string, ssz ); + memcpy( buf+ssz, " (", 2 ); + auto end = PrintFloat( buf+ssz+2, buf+128, percent, 2 ); + memcpy( end, "%)", 3 ); +} + template void View::DrawZoneInfoChildren( const V& children, int64_t ztime ) { @@ -6516,7 +6525,7 @@ void View::DrawZoneInfoChildren( const V& children, int64_t ztime ) TextColoredUnformatted( ImVec4( 1.0f, 1.0f, 0.4f, 1.0f ), "Self time" ); ImGui::NextColumn(); char buf[128]; - sprintf( buf, "%s (%.2f%%)", TimeToString( ztime - ctime ), double( ztime - ctime ) / ztime * 100 ); + PrintStringPercent( buf, TimeToString( ztime - ctime ), double( ztime - ctime ) / ztime * 100 ); ImGui::ProgressBar( double( ztime - ctime ) * rztime, ImVec2( -1, ty ), buf ); ImGui::NextColumn(); for( size_t i=0; isecond.runningTime ), double( tit->second.runningTime ) * rtimespan * 100 ); + PrintStringPercent( buf, TimeToString( tit->second.runningTime ), double( tit->second.runningTime ) * rtimespan * 100 ); ImGui::ProgressBar( double( tit->second.runningTime ) * rtimespan, ImVec2( -1, ty ), buf ); ImGui::NextColumn(); ImGui::TextUnformatted( RealToString( tit->second.runningRegions ) );