diff options
| author | Lioncash <mathew1800@gmail.com> | 2019-06-14 10:53:46 -0400 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2019-06-14 15:04:09 -0400 |
| commit | 5b92d5076a0be89945fa0fc722749dd5fbfcdf4c (patch) | |
| tree | b87080969dd47a01c3a7845d65ef2afdef90928d /Source/Core/Common/Timer.cpp | |
| parent | 925afcae3b7b6ea8dde2cfd236288d924c42fa05 (diff) | |
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.
Diffstat (limited to 'Source/Core/Common/Timer.cpp')
| -rw-r--r-- | Source/Core/Common/Timer.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
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 <cinttypes> +#include "Common/Timer.h" + #include <ctime> #include <string> @@ -16,9 +17,10 @@ #include <sys/time.h> #endif +#include <fmt/format.h> + #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 } |
