From ffabb6c57b59c6ceafd154681c2cde1bd1a65904 Mon Sep 17 00:00:00 2001 From: get <45425365+Minty-Meeo@users.noreply.github.com> Date: Sat, 17 Jun 2023 19:23:49 -0500 Subject: [PATCH] Replace std::ostringstream usage with fmt::format --- Source/Core/AudioCommon/WaveFile.cpp | 8 +++-- Source/Core/Common/Debug/Watches.cpp | 10 +++--- Source/Core/Core/NetPlayClient.cpp | 6 +--- .../ControllerInterface/CoreDevice.cpp | 11 +++---- .../DInput/DInputJoystick.cpp | 33 +++++-------------- Source/Core/UICommon/UICommon.cpp | 8 ++--- 6 files changed, 27 insertions(+), 49 deletions(-) diff --git a/Source/Core/AudioCommon/WaveFile.cpp b/Source/Core/AudioCommon/WaveFile.cpp index 2e67d86519..b2345aca59 100644 --- a/Source/Core/AudioCommon/WaveFile.cpp +++ b/Source/Core/AudioCommon/WaveFile.cpp @@ -6,6 +6,8 @@ #include +#include + #include "Common/CommonTypes.h" #include "Common/FileUtil.h" #include "Common/IOFile.h" @@ -159,9 +161,9 @@ void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count, { Stop(); file_index++; - std::ostringstream filename; - filename << File::GetUserPath(D_DUMPAUDIO_IDX) << basename << file_index << ".wav"; - Start(filename.str(), sample_rate_divisor); + const std::string filename = + fmt::format("{}{}{}.wav", File::GetUserPath(D_DUMPAUDIO_IDX), basename, file_index); + Start(filename, sample_rate_divisor); current_sample_rate_divisor = sample_rate_divisor; } diff --git a/Source/Core/Common/Debug/Watches.cpp b/Source/Core/Common/Debug/Watches.cpp index dddb3f3435..c476665a41 100644 --- a/Source/Core/Common/Debug/Watches.cpp +++ b/Source/Core/Common/Debug/Watches.cpp @@ -7,6 +7,8 @@ #include #include +#include + namespace Common::Debug { Watch::Watch(u32 address_, std::string name_, State is_enabled_) @@ -107,13 +109,9 @@ void Watches::LoadFromStrings(const std::vector& watches) std::vector Watches::SaveToStrings() const { std::vector watches; + watches.reserve(m_watches.size()); for (const auto& watch : m_watches) - { - std::ostringstream ss; - ss.imbue(std::locale::classic()); - ss << std::hex << watch.address << " " << watch.name; - watches.push_back(ss.str()); - } + watches.emplace_back(fmt::format("{:x} {}", watch.address, watch.name)); return watches; } diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index ff78728c80..014bd3b523 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -535,10 +534,7 @@ void NetPlayClient::OnChatMessage(sf::Packet& packet) INFO_LOG_FMT(NETPLAY, "Player {} ({}) wrote: {}", player.name, player.pid, msg); // add to gui - std::ostringstream ss; - ss << player.name << '[' << char(pid + '0') << "]: " << msg; - - m_dialog->AppendChat(ss.str()); + m_dialog->AppendChat(fmt::format("{}[{}]: {}", player.name, pid, msg)); } void NetPlayClient::OnChunkedDataStart(sf::Packet& packet) diff --git a/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp b/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp index 222791f03f..28b91332cc 100644 --- a/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp +++ b/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp @@ -162,15 +162,12 @@ void Device::AddCombinedInput(std::string name, const std::pair -1) - ss << cid; - ss << '/' << name; - - return ss.str(); + return fmt::format("{}/{}/{}", source, cid, name); + else + return fmt::format("{}//{}", source, name); } // diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp index abef48f157..eb60721b2f 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp @@ -7,9 +7,10 @@ #include #include #include -#include #include +#include + #include "Common/HRWrap.h" #include "Common/Logging/Log.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" @@ -266,37 +267,21 @@ void Joystick::UpdateInput() std::string Joystick::Button::GetName() const { - std::ostringstream ss; - ss << "Button " << (int)m_index; - return ss.str(); + return fmt::format("Button {}", m_index); } std::string Joystick::Axis::GetName() const { - std::ostringstream ss; - // axis - if (m_index < 6) - { - ss << "Axis " << (char)('X' + (m_index % 3)); - if (m_index > 2) - ss << 'r'; - } - // slider - else - { - ss << "Slider " << (int)(m_index - 6); - } - - ss << (m_range < 0 ? '-' : '+'); - return ss.str(); + const char sign = m_range < 0 ? '-' : '+'; + if (m_index < 6) // axis + return fmt::format("Axis {:c}{}{:c}", 'X' + m_index % 3, m_index > 2 ? "r" : "", sign); + else // slider + return fmt::format("Slider {}{:c}", m_index - 6, sign); } std::string Joystick::Hat::GetName() const { - char tmpstr[] = "Hat . ."; - tmpstr[4] = (char)('0' + m_index); - tmpstr[6] = "NESW"[m_direction]; - return tmpstr; + return fmt::format("Hat {} {:c}", m_index, "NESW"[m_direction]); } // get / set state diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 464646eb17..2acd69f2c2 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -16,6 +16,8 @@ #include #endif +#include + #include "Common/Common.h" #include "Common/CommonPaths.h" #include "Common/Config/Config.h" @@ -551,10 +553,8 @@ std::string FormatSize(u64 bytes, int decimals) // Don't need exact values, only 5 most significant digits const double unit_size = std::pow(2, unit * 10); - std::ostringstream ss; - ss << std::fixed << std::setprecision(decimals); - ss << bytes / unit_size << ' ' << Common::GetStringT(unit_symbols[unit]); - return ss.str(); + return fmt::format("{:.{}Lf} {}", bytes / unit_size, decimals, + Common::GetStringT(unit_symbols[unit])); } } // namespace UICommon