From 5b92d5076a0be89945fa0fc722749dd5fbfcdf4c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 14 Jun 2019 10:53:46 -0400 Subject: Common: Use fmt where applicable Begins the transition to using fmt for string formatting where applicable. Given fmt supports formatting std::string instances out of the box, we can remove now-unnecessary calls to .c_str() and .data(). Note that this change does not touch the actual logging subsystem aside from converting the final StringFromFormat call in the process over to fmt::format. Given our logging system is heavily used throughout the entire codebase, and converting that over will be quite a large change by itself, this will be tackled near the end of the conversion process. --- Source/Core/Common/Timer.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'Source/Core/Common/Timer.cpp') diff --git a/Source/Core/Common/Timer.cpp b/Source/Core/Common/Timer.cpp index 1d25cc0f71..794f2dfd49 100644 --- a/Source/Core/Common/Timer.cpp +++ b/Source/Core/Common/Timer.cpp @@ -2,7 +2,8 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include +#include "Common/Timer.h" + #include #include @@ -16,9 +17,10 @@ #include #endif +#include + #include "Common/CommonTypes.h" #include "Common/StringUtil.h" -#include "Common/Timer.h" namespace Common { @@ -149,9 +151,8 @@ std::string Timer::GetTimeElapsedFormatted() const // Hours u32 Hours = Minutes / 60; - std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03" PRIu64, Hours, Minutes % 60, - Seconds % 60, Milliseconds % 1000); - return TmpStr; + return fmt::format("{:02}:{:02}:{:02}:{:03}", Hours, Minutes % 60, Seconds % 60, + Milliseconds % 1000); } // Get current time @@ -217,15 +218,15 @@ std::string Timer::GetTimeFormatted() #ifdef _WIN32 struct timeb tp; (void)::ftime(&tp); - return UTF16ToUTF8(tmp) + StringFromFormat(":%03i", tp.millitm); + return UTF16ToUTF8(tmp) + fmt::format(":{:03}", tp.millitm); #elif defined __APPLE__ struct timeval t; (void)gettimeofday(&t, nullptr); - return StringFromFormat("%s:%03d", tmp, (int)(t.tv_usec / 1000)); + return fmt::format("{}:{:03}", tmp, t.tv_usec / 1000); #else struct timespec t; (void)clock_gettime(CLOCK_MONOTONIC, &t); - return StringFromFormat("%s:%03d", tmp, (int)(t.tv_nsec / 1000000)); + return fmt::format("{}:{:03}", tmp, t.tv_nsec / 1000000); #endif } -- cgit v1.2.3