mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-12 21:31:39 +00:00
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.
This commit is contained in:
parent
925afcae3b
commit
5b92d5076a
13 changed files with 287 additions and 263 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue