Common: Drop String, add SmallString

This commit is contained in:
Stenzek
2023-09-20 23:49:14 +10:00
parent 3c68543491
commit ac0601f408
55 changed files with 1500 additions and 2062 deletions

View File

@@ -666,7 +666,7 @@ bool CDImagePBP::OpenDisc(u32 index, Error* error)
if (m_disc_offsets.size() > 1)
{
std::string sbi_path(Path::StripExtension(m_filename));
sbi_path += TinyString::FromFormat("_%u.sbi", index + 1);
sbi_path += TinyString::from_fmt("_%u.sbi", index + 1).view();
m_sbi.LoadSBI(sbi_path.c_str());
}
else

View File

@@ -71,10 +71,10 @@ void File::SetError(u32 line_number, Error* error, const char* format, ...)
std::va_list ap;
SmallString str;
va_start(ap, format);
str.FormatVA(format, ap);
str.format_va(format, ap);
va_end(ap);
Log_ErrorPrintf("Cue parse error at line %u: %s", line_number, str.GetCharArray());
Log_ErrorPrintf("Cue parse error at line %u: %s", line_number, str.c_str());
Error::SetString(error, fmt::format("Cue parse error at line {}: {}", line_number, str));
}

View File

@@ -17,7 +17,7 @@
#include "common/log.h"
#include "common/path.h"
#include "common/scoped_guard.h"
#include "common/string.h"
#include "common/small_string.h"
#include "common/string_util.h"
#include "D3D12MemAlloc.h"

View File

@@ -265,7 +265,7 @@ void GPUDevice::OpenShaderCache(const std::string_view& base_path, u32 version)
if (m_features.pipeline_cache)
{
const std::string pc_filename =
Path::Combine(base_path, TinyString::FromFmt("{}.bin", GetShaderCacheBaseName("pipelines")));
Path::Combine(base_path, TinyString::from_fmt("{}.bin", GetShaderCacheBaseName("pipelines")));
if (FileSystem::FileExists(pc_filename.c_str()))
{
Log_InfoPrintf("Removing old pipeline cache '%s'", pc_filename.c_str());
@@ -284,7 +284,7 @@ void GPUDevice::OpenShaderCache(const std::string_view& base_path, u32 version)
if (m_features.pipeline_cache && !base_path.empty())
{
const std::string basename = GetShaderCacheBaseName("pipelines");
const std::string filename = Path::Combine(base_path, TinyString::FromFmt("{}.bin", basename));
const std::string filename = Path::Combine(base_path, TinyString::from_fmt("{}.bin", basename));
if (ReadPipelineCache(filename))
s_pipeline_cache_path = std::move(filename);
else

View File

@@ -2375,12 +2375,12 @@ void ImGuiFullscreen::DrawBackgroundProgressDialogs(ImVec2& position, float spac
dl->AddRectFilled(pos, ImVec2(pos.x + fraction * (box_end.x - pos.x), box_end.y),
ImGui::GetColorU32(UISecondaryColor));
const auto text = TinyString::FromFmt("{}%", static_cast<int>(std::round(fraction * 100.0f)));
const auto text = TinyString::from_fmt("{}%", static_cast<int>(std::round(fraction * 100.0f)));
const ImVec2 text_size(ImGui::CalcTextSize(text));
const ImVec2 text_pos(pos.x + ((box_end.x - pos.x) / 2.0f) - (text_size.x / 2.0f),
pos.y + ((box_end.y - pos.y) / 2.0f) - (text_size.y / 2.0f));
dl->AddText(g_medium_font, g_medium_font->FontSize, text_pos, ImGui::GetColorU32(UIPrimaryTextColor),
text.GetCharArray(), text.GetCharArray() + text.GetLength());
text.c_str(), text.end_ptr());
}
else
{

View File

@@ -1714,9 +1714,9 @@ bool InputManager::MigrateBindings(SettingsInterface& si)
if (bnum >= std::size(button_mapping))
continue;
new_bind.Fmt("SDL-{}/{}", cnum, button_mapping[bnum]);
new_bind.fmt("SDL-{}/{}", cnum, button_mapping[bnum]);
si.SetStringValue(new_section.c_str(), new_key, new_bind);
Log_DevPrintf("%s -> %s", old_bind.c_str(), new_bind.GetCharArray());
Log_DevPrintf("%s -> %s", old_bind.c_str(), new_bind.c_str());
num_changes++;
}
else if (std::sscanf(old_bind.c_str(), "Controller%u/%cAxis%u", &cnum, &dir, &bnum) == 3)
@@ -1724,16 +1724,16 @@ bool InputManager::MigrateBindings(SettingsInterface& si)
if (bnum >= std::size(axis_mapping))
continue;
new_bind.Fmt("SDL-{}/{}{}", cnum, dir, axis_mapping[bnum]);
new_bind.fmt("SDL-{}/{}{}", cnum, dir, axis_mapping[bnum]);
si.SetStringValue(new_section.c_str(), new_key, new_bind);
Log_DevPrintf("%s -> %s", old_bind.c_str(), new_bind.GetCharArray());
Log_DevPrintf("%s -> %s", old_bind.c_str(), new_bind.c_str());
num_changes++;
}
else if (StringUtil::StartsWith(old_bind.c_str(), "Keyboard/Keypad+"))
{
new_bind.Fmt("Keyboard/Numpad{}", old_bind.substr(16));
new_bind.fmt("Keyboard/Numpad{}", old_bind.substr(16));
si.SetStringValue(new_section.c_str(), new_key, new_bind);
Log_DevPrintf("%s -> %s", old_bind.c_str(), new_bind.GetCharArray());
Log_DevPrintf("%s -> %s", old_bind.c_str(), new_bind.c_str());
num_changes++;
}
else if (StringUtil::StartsWith(old_bind.c_str(), "Keyboard/"))
@@ -1764,12 +1764,12 @@ bool InputManager::MigrateBindings(SettingsInterface& si)
if (bnum >= std::size(axis_mapping))
continue;
new_bind.Fmt("SDL-{}/-{}", cnum, axis_mapping[bnum]);
new_bind.fmt("SDL-{}/-{}", cnum, axis_mapping[bnum]);
si.SetStringValue(new_section.c_str(), new_neg_key, new_bind);
new_bind.Fmt("SDL-{}/+{}", cnum, axis_mapping[bnum]);
new_bind.fmt("SDL-{}/+{}", cnum, axis_mapping[bnum]);
si.SetStringValue(new_section.c_str(), new_pos_key, new_bind);
Log_DevPrintf("%s -> %s", old_bind.c_str(), new_bind.GetCharArray());
Log_DevPrintf("%s -> %s", old_bind.c_str(), new_bind.c_str());
num_changes++;
}
}
@@ -1780,9 +1780,9 @@ bool InputManager::MigrateBindings(SettingsInterface& si)
unsigned cnum;
if (std::sscanf(rumble_source.c_str(), "Controller%u", &cnum) == 1)
{
new_bind.Fmt("SDL-{}/LargeMotor", cnum);
new_bind.fmt("SDL-{}/LargeMotor", cnum);
si.SetStringValue(new_section.c_str(), "LargeMotor", new_bind);
new_bind.Fmt("SDL-{}/SmallMotor", cnum);
new_bind.fmt("SDL-{}/SmallMotor", cnum);
si.SetStringValue(new_section.c_str(), "SmallMotor", new_bind);
num_changes++;
}

View File

@@ -12,7 +12,7 @@
#include "common/log.h"
#include "common/path.h"
#include "common/scoped_guard.h"
#include "common/string.h"
#include "common/small_string.h"
#include "common/string_util.h"
#include "fmt/format.h"
@@ -358,7 +358,7 @@ GLuint OpenGLDevice::CompileProgram(const GPUPipeline::GraphicsConfig& plconfig)
{
glBindAttribLocation(
program_id, i,
TinyString::FromFmt("{}{}", semantic_vars[static_cast<u8>(va.semantic.GetValue())], va.semantic_index));
TinyString::from_fmt("{}{}", semantic_vars[static_cast<u8>(va.semantic.GetValue())], va.semantic_index));
}
}
@@ -418,7 +418,7 @@ void OpenGLDevice::PostLinkProgram(const GPUPipeline::GraphicsConfig& plconfig,
const u32 num_textures = std::max<u32>(GetActiveTexturesForLayout(plconfig.layout), 1);
for (u32 i = 0; i < num_textures; i++)
{
location = glGetUniformLocation(program_id, TinyString::FromFmt("samp{}", i));
location = glGetUniformLocation(program_id, TinyString::from_fmt("samp{}", i));
if (location >= 0)
glUniform1i(location, i);
}

View File

@@ -5,6 +5,7 @@
#include "common/types.h"
#include "fmt/core.h"
#include "fmt/format.h"
#include <array>

View File

@@ -6,7 +6,7 @@
#include "cocoa_tools.h"
#include "common/log.h"
#include "common/string.h"
#include "common/small_string.h"
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <Cocoa/Cocoa.h>

View File

@@ -6,7 +6,7 @@
#include "common/log.h"
#include "common/scoped_guard.h"
#include "common/string.h"
#include "common/small_string.h"
#include <cinttypes>
#include <spawn.h>

View File

@@ -2,7 +2,7 @@
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "common/log.h"
#include "common/string.h"
#include "common/small_string.h"
#include "common/string_util.h"
#include "platform_misc.h"
#include <cinttypes>

View File

@@ -19,7 +19,7 @@
#include "common/file_system.h"
#include "common/log.h"
#include "common/path.h"
#include "common/string.h"
#include "common/small_string.h"
#include "common/string_util.h"
#include "common/timer.h"
#include "fmt/format.h"
@@ -120,20 +120,20 @@ TinyString PostProcessing::ValueToString(ShaderOption::Type type, u32 vector_siz
for (u32 i = 0; i < vector_size; i++)
{
if (i > 0)
ret.AppendCharacter(',');
ret.append(',');
switch (type)
{
case ShaderOption::Type::Bool:
ret.AppendString((value[i].int_value != 0) ? "true" : "false");
ret.append((value[i].int_value != 0) ? "true" : "false");
break;
case ShaderOption::Type::Int:
ret.AppendFmtString("{}", value[i].int_value);
ret.append_fmt("{}", value[i].int_value);
break;
case ShaderOption::Type::Float:
ret.AppendFmtString("{}", value[i].float_value);
ret.append_fmt("{}", value[i].float_value);
break;
default:
@@ -207,7 +207,7 @@ std::vector<std::pair<std::string, std::string>> PostProcessing::GetAvailableSha
TinyString PostProcessing::GetStageConfigSection(u32 index)
{
return TinyString::FromFmt("PostProcessing/Stage{}", index + 1);
return TinyString::from_fmt("PostProcessing/Stage{}", index + 1);
}
void PostProcessing::CopyStageConfig(SettingsInterface& si, u32 old_index, u32 new_index)

View File

@@ -3,7 +3,7 @@
#include "state_wrapper.h"
#include "common/log.h"
#include "common/string.h"
#include "common/small_string.h"
#include <cinttypes>
#include <cstring>
Log_SetChannel(StateWrapper);
@@ -67,14 +67,14 @@ void StateWrapper::Do(std::string* value_ptr)
value_ptr->resize(std::strlen(&(*value_ptr)[0]));
}
void StateWrapper::Do(String* value_ptr)
void StateWrapper::Do(SmallStringBase* value_ptr)
{
u32 length = static_cast<u32>(value_ptr->GetLength());
u32 length = static_cast<u32>(value_ptr->length());
Do(&length);
if (m_mode == Mode::Read)
value_ptr->Resize(length);
DoBytes(value_ptr->GetWriteableCharArray(), length);
value_ptr->UpdateSize();
value_ptr->resize(length);
DoBytes(value_ptr->data(), length);
value_ptr->update_size();
}
bool StateWrapper::DoMarker(const char* marker)
@@ -84,11 +84,11 @@ bool StateWrapper::DoMarker(const char* marker)
if (m_error)
return false;
if (m_mode == Mode::Write || file_value.Compare(marker))
if (m_mode == Mode::Write || file_value.equals(marker))
return true;
Log_ErrorPrintf("Marker mismatch at offset %" PRIu64 ": found '%s' expected '%s'", m_stream->GetPosition(),
file_value.GetCharArray(), marker);
file_value.c_str(), marker);
return false;
}

View File

@@ -12,7 +12,7 @@
#include <type_traits>
#include <vector>
class String;
class SmallStringBase;
class StateWrapper
{
@@ -108,7 +108,7 @@ public:
void Do(bool* value_ptr);
void Do(std::string* value_ptr);
void Do(String* value_ptr);
void Do(SmallStringBase* value_ptr);
template<typename T, size_t N>
void Do(std::array<T, N>* data)

View File

@@ -17,7 +17,7 @@
#include "common/log.h"
#include "common/path.h"
#include "common/scoped_guard.h"
#include "common/string.h"
#include "common/small_string.h"
#include "fmt/format.h"
@@ -662,7 +662,7 @@ bool VulkanDevice::CreateCommandBuffers()
LOG_VULKAN_ERROR(res, "vkCreateCommandPool failed: ");
return false;
}
Vulkan::SetObjectName(m_device, resources.command_pool, TinyString::FromFmt("Frame Command Pool {}", frame_index));
Vulkan::SetObjectName(m_device, resources.command_pool, TinyString::from_fmt("Frame Command Pool {}", frame_index));
VkCommandBufferAllocateInfo buffer_info = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr,
resources.command_pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY,
@@ -677,7 +677,7 @@ bool VulkanDevice::CreateCommandBuffers()
for (u32 i = 0; i < resources.command_buffers.size(); i++)
{
Vulkan::SetObjectName(m_device, resources.command_buffers[i],
TinyString::FromFmt("Frame {} {}Command Buffer", frame_index, (i == 0) ? "Init" : ""));
TinyString::from_fmt("Frame {} {}Command Buffer", frame_index, (i == 0) ? "Init" : ""));
}
VkFenceCreateInfo fence_info = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
@@ -688,7 +688,7 @@ bool VulkanDevice::CreateCommandBuffers()
LOG_VULKAN_ERROR(res, "vkCreateFence failed: ");
return false;
}
Vulkan::SetObjectName(m_device, resources.fence, TinyString::FromFmt("Frame Fence {}", frame_index));
Vulkan::SetObjectName(m_device, resources.fence, TinyString::from_fmt("Frame Fence {}", frame_index));
if (!m_optional_extensions.vk_khr_push_descriptor)
{
@@ -707,7 +707,7 @@ bool VulkanDevice::CreateCommandBuffers()
return false;
}
Vulkan::SetObjectName(m_device, resources.descriptor_pool,
TinyString::FromFmt("Frame Descriptor Pool {}", frame_index));
TinyString::from_fmt("Frame Descriptor Pool {}", frame_index));
}
++frame_index;