Misc: Pass string_view by value

This commit is contained in:
Stenzek
2024-05-05 20:21:54 +10:00
parent e4d940a476
commit ca3cfbaa99
111 changed files with 543 additions and 542 deletions

View File

@@ -118,7 +118,7 @@ struct AchievementProgressIndicator
};
} // namespace
static void ReportError(const std::string_view& sv);
static void ReportError(std::string_view sv);
template<typename... T>
static void ReportFmtError(fmt::format_string<T...> fmt, T&&... args);
template<typename... T>
@@ -242,7 +242,7 @@ const rc_client_user_game_summary_t& Achievements::GetGameSummary()
return s_game_summary;
}
void Achievements::ReportError(const std::string_view& sv)
void Achievements::ReportError(std::string_view sv)
{
std::string error = fmt::format("Achievements error: {}", sv);
Log_ErrorPrint(error.c_str());
@@ -1576,7 +1576,7 @@ std::string Achievements::GetAchievementBadgePath(const rc_client_achievement_t*
return path;
}
std::string Achievements::GetUserBadgePath(const std::string_view& username)
std::string Achievements::GetUserBadgePath(std::string_view username)
{
// definitely want to sanitize usernames... :)
std::string path;

View File

@@ -17,7 +17,7 @@ const std::string& GetGameIconPath();
std::string GetAchievementBadgePath(const rc_client_achievement_t* achievement, int state,
bool download_if_missing = true);
std::string GetUserBadgePath(const std::string_view& username);
std::string GetUserBadgePath(std::string_view username);
std::string GetLeaderboardUserBadgePath(const rc_client_leaderboard_entry_t* entry);
void OpenLeaderboard(const rc_client_leaderboard_t* lboard);

View File

@@ -369,7 +369,7 @@ void Bus::AddTTYCharacter(char ch)
}
}
void Bus::AddTTYString(const std::string_view& str)
void Bus::AddTTYString(std::string_view str)
{
for (char ch : str)
AddTTYCharacter(ch);

View File

@@ -209,6 +209,6 @@ std::optional<PhysicalMemoryAddress> SearchMemory(PhysicalMemoryAddress start_ad
// TTY Logging.
void AddTTYCharacter(char ch);
void AddTTYString(const std::string_view& str);
void AddTTYString(std::string_view str);
} // namespace Bus

View File

@@ -296,7 +296,7 @@ static void ResampleXAADPCM(const s16* frames_in, u32 num_frames_in);
static TinyString LBAToMSFString(CDImage::LBA lba);
static void CreateFileMap();
static void CreateFileMap(IsoReader& iso, const std::string_view& dir);
static void CreateFileMap(IsoReader& iso, std::string_view dir);
static const std::string* LookupFileMap(u32 lba, u32* start_lba, u32* end_lba);
static std::unique_ptr<TimingEvent> s_command_event;
@@ -3317,7 +3317,7 @@ void CDROM::CreateFileMap()
Log_DevFmt("Found {} files", s_file_map.size());
}
void CDROM::CreateFileMap(IsoReader& iso, const std::string_view& dir)
void CDROM::CreateFileMap(IsoReader& iso, std::string_view dir)
{
for (auto& [path, entry] : iso.GetEntriesInDirectory(dir))
{

View File

@@ -157,7 +157,7 @@ std::vector<std::pair<std::string, std::string>> Controller::GetControllerTypeNa
return ret;
}
std::optional<u32> Controller::GetBindIndex(ControllerType type, const std::string_view& bind_name)
std::optional<u32> Controller::GetBindIndex(ControllerType type, std::string_view bind_name)
{
const ControllerInfo* info = GetControllerInfo(type);
if (!info)
@@ -172,7 +172,7 @@ std::optional<u32> Controller::GetBindIndex(ControllerType type, const std::stri
return std::nullopt;
}
Controller::VibrationCapabilities Controller::GetControllerVibrationCapabilities(const std::string_view& type)
Controller::VibrationCapabilities Controller::GetControllerVibrationCapabilities(std::string_view type)
{
const ControllerInfo* info = GetControllerInfo(type);
return info ? info->vibration_caps : VibrationCapabilities::NoVibration;

View File

@@ -102,10 +102,10 @@ public:
static std::vector<std::pair<std::string, std::string>> GetControllerTypeNames();
/// Gets the integer code for an axis in the specified controller type.
static std::optional<u32> GetBindIndex(ControllerType type, const std::string_view& bind_name);
static std::optional<u32> GetBindIndex(ControllerType type, std::string_view bind_name);
/// Returns the vibration configuration for the specified controller type.
static VibrationCapabilities GetControllerVibrationCapabilities(const std::string_view& type);
static VibrationCapabilities GetControllerVibrationCapabilities(std::string_view type);
/// Returns general information for the specified controller type.
static const ControllerInfo* GetControllerInfo(ControllerType type);

View File

@@ -229,8 +229,8 @@ static void DrawLandingWindow();
static void DrawStartGameWindow();
static void DrawExitWindow();
static void DrawPauseMenu();
static void ExitFullscreenAndOpenURL(const std::string_view& url);
static void CopyTextToClipboard(std::string title, const std::string_view& text);
static void ExitFullscreenAndOpenURL(std::string_view url);
static void CopyTextToClipboard(std::string title, std::string_view text);
static void DrawAboutWindow();
static void OpenAboutWindow();
static void FixStateIfPaused();
@@ -293,7 +293,7 @@ static void SwitchToSettings();
static void SwitchToGameSettings();
static void SwitchToGameSettings(const GameList::Entry* entry);
static void SwitchToGameSettingsForPath(const std::string& path);
static void SwitchToGameSettingsForSerial(const std::string_view& serial);
static void SwitchToGameSettingsForSerial(std::string_view serial);
static void DrawSettingsWindow();
static void DrawSummarySettingsPage();
static void DrawInterfaceSettingsPage();
@@ -391,8 +391,8 @@ static void DrawFolderSetting(SettingsInterface* bsi, const char* title, const c
static void PopulateGraphicsAdapterList();
static void PopulateGameListDirectoryCache(SettingsInterface* si);
static void PopulatePostProcessingChain(SettingsInterface* si);
static void BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::Type type, const std::string_view& section,
const std::string_view& key, const std::string_view& display_name);
static void BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::Type type, std::string_view section,
std::string_view key, std::string_view display_name);
static void DrawInputBindingWindow();
static void DrawInputBindingButton(SettingsInterface* bsi, InputBindingInfo::Type type, const char* section,
const char* name, const char* display_name, const char* icon_name,
@@ -1754,9 +1754,8 @@ void FullscreenUI::ClearInputBindingVariables()
s_input_binding_value_ranges = {};
}
void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::Type type,
const std::string_view& section, const std::string_view& key,
const std::string_view& display_name)
void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::Type type, std::string_view section,
std::string_view key, std::string_view display_name)
{
if (s_input_binding_type != InputBindingInfo::Type::Unknown)
{
@@ -2738,7 +2737,7 @@ void FullscreenUI::SwitchToSettings()
s_settings_page = SettingsPage::Interface;
}
void FullscreenUI::SwitchToGameSettingsForSerial(const std::string_view& serial)
void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial)
{
s_game_settings_entry.reset();
s_game_settings_interface = std::make_unique<INISettingsInterface>(System::GetGameSettingsPath(serial));
@@ -6837,7 +6836,7 @@ void FullscreenUI::OpenAboutWindow()
s_about_window_open = true;
}
void FullscreenUI::ExitFullscreenAndOpenURL(const std::string_view& url)
void FullscreenUI::ExitFullscreenAndOpenURL(std::string_view url)
{
Host::RunOnCPUThread([url = std::string(url)]() {
if (Host::IsFullscreen())
@@ -6847,7 +6846,7 @@ void FullscreenUI::ExitFullscreenAndOpenURL(const std::string_view& url)
});
}
void FullscreenUI::CopyTextToClipboard(std::string title, const std::string_view& text)
void FullscreenUI::CopyTextToClipboard(std::string title, std::string_view text)
{
if (Host::CopyTextToClipboard(text))
ShowToast(std::string(), std::move(title));

View File

@@ -37,8 +37,8 @@ enum : u32
GAME_DATABASE_CACHE_VERSION = 7,
};
static Entry* GetMutableEntry(const std::string_view& serial);
static const Entry* GetEntryForId(const std::string_view& code);
static Entry* GetMutableEntry(std::string_view serial);
static const Entry* GetEntryForId(std::string_view code);
static bool LoadFromCache();
static bool SaveToCache();
@@ -110,7 +110,7 @@ ALWAYS_INLINE std::string_view to_stringview(const c4::substr& s)
return std::string_view(s.data(), s.size());
}
ALWAYS_INLINE c4::csubstr to_csubstr(const std::string_view& sv)
ALWAYS_INLINE c4::csubstr to_csubstr(std::string_view sv)
{
return c4::csubstr(sv.data(), sv.length());
}
@@ -239,7 +239,7 @@ void GameDatabase::Unload()
s_loaded = false;
}
const GameDatabase::Entry* GameDatabase::GetEntryForId(const std::string_view& code)
const GameDatabase::Entry* GameDatabase::GetEntryForId(std::string_view code)
{
if (code.empty())
return nullptr;
@@ -307,14 +307,14 @@ const GameDatabase::Entry* GameDatabase::GetEntryForGameDetails(const std::strin
return nullptr;
}
const GameDatabase::Entry* GameDatabase::GetEntryForSerial(const std::string_view& serial)
const GameDatabase::Entry* GameDatabase::GetEntryForSerial(std::string_view serial)
{
EnsureLoaded();
return GetMutableEntry(serial);
}
GameDatabase::Entry* GameDatabase::GetMutableEntry(const std::string_view& serial)
GameDatabase::Entry* GameDatabase::GetMutableEntry(std::string_view serial)
{
for (Entry& entry : s_entries)
{

View File

@@ -96,7 +96,7 @@ void Unload();
const Entry* GetEntryForDisc(CDImage* image);
const Entry* GetEntryForGameDetails(const std::string& id, u64 hash);
const Entry* GetEntryForSerial(const std::string_view& serial);
const Entry* GetEntryForSerial(std::string_view serial);
std::string GetSerialForDisc(CDImage* image);
std::string GetSerialForPath(const char* path);

View File

@@ -117,7 +117,7 @@ bool GameList::IsGameListLoaded()
return s_game_list_loaded;
}
bool GameList::IsScannableFilename(const std::string_view& path)
bool GameList::IsScannableFilename(std::string_view path)
{
// we don't scan bin files because they'll duplicate
if (StringUtil::EndsWithNoCase(path, ".bin"))
@@ -707,7 +707,7 @@ std::string GameList::GetCoverImagePathForEntry(const Entry* entry)
return GetCoverImagePath(entry->path, entry->serial, entry->title);
}
static std::string GetFullCoverPath(const std::string_view& filename, const std::string_view& extension)
static std::string GetFullCoverPath(std::string_view filename, std::string_view extension)
{
return fmt::format("{}" FS_OSPATH_SEPARATOR_STR "{}.{}", EmuFolders::Covers, filename, extension);
}

View File

@@ -68,7 +68,7 @@ struct Entry
const char* GetEntryTypeName(EntryType type);
const char* GetEntryTypeDisplayName(EntryType type);
bool IsScannableFilename(const std::string_view& path);
bool IsScannableFilename(std::string_view path);
/// Populates a game list entry struct with information from the iso/elf.
/// Do *not* call while the system is running, it will mess with CDVD state.

View File

@@ -3,8 +3,8 @@
#include "gdb_protocol.h"
#include "bus.h"
#include "cpu_core_private.h"
#include "cpu_core.h"
#include "cpu_core_private.h"
#include "system.h"
#include "common/log.h"
@@ -20,15 +20,16 @@
Log_SetChannel(GDBProtocol);
namespace GDBProtocol
{
namespace GDBProtocol {
static u8* GetMemoryPointer(PhysicalMemoryAddress address, u32 length)
{
auto region = Bus::GetMemoryRegionForAddress(address);
if (region) {
if (region)
{
u8* data = GetMemoryRegionPointer(*region);
if (data && (address + length <= GetMemoryRegionEnd(*region))) {
if (data && (address + length <= GetMemoryRegionEnd(*region)))
{
return data + (address - GetMemoryRegionStart(*region));
}
}
@@ -36,34 +37,38 @@ static u8* GetMemoryPointer(PhysicalMemoryAddress address, u32 length)
return nullptr;
}
static u8 ComputeChecksum(const std::string_view& str)
static u8 ComputeChecksum(std::string_view str)
{
u8 checksum = 0;
for (char c : str) {
for (char c : str)
{
checksum = (checksum + c) % 256;
}
return checksum;
}
static std::optional<std::string_view> DeserializePacket(const std::string_view& in)
static std::optional<std::string_view> DeserializePacket(std::string_view in)
{
if ((in.size() < 4) || (in[0] != '$') || (in[in.size()-3] != '#')) {
if ((in.size() < 4) || (in[0] != '$') || (in[in.size() - 3] != '#'))
{
return std::nullopt;
}
std::string_view data = in.substr(1, in.size()-4);
std::string_view data = in.substr(1, in.size() - 4);
u8 packetChecksum = StringUtil::FromChars<u8>(in.substr(in.size()-2, 2), 16).value_or(0);
u8 packetChecksum = StringUtil::FromChars<u8>(in.substr(in.size() - 2, 2), 16).value_or(0);
u8 computedChecksum = ComputeChecksum(data);
if (packetChecksum == computedChecksum) {
return { data };
if (packetChecksum == computedChecksum)
{
return {data};
}
else {
else
{
return std::nullopt;
}
}
static std::string SerializePacket(const std::string_view& in)
static std::string SerializePacket(std::string_view in)
{
std::stringstream ss;
ss << '$' << in << '#' << TinyString::from_format("{:02x}", ComputeChecksum(in));
@@ -71,7 +76,7 @@ static std::string SerializePacket(const std::string_view& in)
}
/// List of GDB remote protocol registers for MIPS III (excluding FP).
static const std::array<u32*, 38> REGISTERS {
static const std::array<u32*, 38> REGISTERS{
&CPU::g_state.regs.r[0],
&CPU::g_state.regs.r[1],
&CPU::g_state.regs.r[2],
@@ -117,53 +122,59 @@ static const std::array<u32*, 38> REGISTERS {
constexpr int NUM_GDB_REGISTERS = 73;
/// Get stop reason.
static std::optional<std::string> Cmd$_questionMark(const std::string_view& data)
static std::optional<std::string> Cmd$_questionMark(std::string_view data)
{
return { "S02" };
return {"S02"};
}
/// Get general registers.
static std::optional<std::string> Cmd$g(const std::string_view& data)
static std::optional<std::string> Cmd$g(std::string_view data)
{
std::stringstream ss;
for (u32* reg : REGISTERS) {
for (u32* reg : REGISTERS)
{
// Data is in host order (little endian).
ss << StringUtil::EncodeHex(reinterpret_cast<u8*>(reg), 4);
}
// Pad with dummy data (FP registers stuff).
for (int i = 0; i < NUM_GDB_REGISTERS - static_cast<int>(REGISTERS.size()); i++) {
for (int i = 0; i < NUM_GDB_REGISTERS - static_cast<int>(REGISTERS.size()); i++)
{
ss << "00000000";
}
return { ss.str() };
return {ss.str()};
}
/// Set general registers.
static std::optional<std::string> Cmd$G(const std::string_view& data)
static std::optional<std::string> Cmd$G(std::string_view data)
{
if (data.size() == NUM_GDB_REGISTERS*8) {
if (data.size() == NUM_GDB_REGISTERS * 8)
{
int offset = 0;
for (u32* reg : REGISTERS) {
for (u32* reg : REGISTERS)
{
// Data is in host order (little endian).
auto value = StringUtil::DecodeHex({data.data()+offset, 8});
if (value) {
auto value = StringUtil::DecodeHex({data.data() + offset, 8});
if (value)
{
*reg = *reinterpret_cast<u32*>(&(*value)[0]);
}
offset += 8;
}
}
else {
Log_ErrorPrintf("Wrong payload size for 'G' command, expected %d got %zu", NUM_GDB_REGISTERS*8, data.size());
else
{
Log_ErrorPrintf("Wrong payload size for 'G' command, expected %d got %zu", NUM_GDB_REGISTERS * 8, data.size());
}
return { "" };
return {""};
}
/// Get memory.
static std::optional<std::string> Cmd$m(const std::string_view& data)
static std::optional<std::string> Cmd$m(std::string_view data)
{
std::stringstream ss{std::string{data}};
std::string dataAddress, dataLength;
@@ -174,20 +185,22 @@ static std::optional<std::string> Cmd$m(const std::string_view& data)
auto address = StringUtil::FromChars<VirtualMemoryAddress>(dataAddress, 16);
auto length = StringUtil::FromChars<u32>(dataLength, 16);
if (address && length) {
if (address && length)
{
PhysicalMemoryAddress phys_addr = *address & CPU::PHYSICAL_MEMORY_ADDRESS_MASK;
u32 phys_length = *length;
u8* ptr_data = GetMemoryPointer(phys_addr, phys_length);
if (ptr_data) {
return { StringUtil::EncodeHex(ptr_data, phys_length) };
if (ptr_data)
{
return {StringUtil::EncodeHex(ptr_data, phys_length)};
}
}
return { "E00" };
return {"E00"};
}
/// Set memory.
static std::optional<std::string> Cmd$M(const std::string_view& data)
static std::optional<std::string> Cmd$M(std::string_view data)
{
std::stringstream ss{std::string{data}};
std::string dataAddress, dataLength, dataPayload;
@@ -200,95 +213,101 @@ static std::optional<std::string> Cmd$M(const std::string_view& data)
auto length = StringUtil::FromChars<u32>(dataLength, 16);
auto payload = StringUtil::DecodeHex(dataPayload);
if (address && length && payload && (payload->size() == *length)) {
if (address && length && payload && (payload->size() == *length))
{
u32 phys_addr = *address & CPU::PHYSICAL_MEMORY_ADDRESS_MASK;
u32 phys_length = *length;
u8* ptr_data = GetMemoryPointer(phys_addr, phys_length);
if (ptr_data) {
if (ptr_data)
{
memcpy(ptr_data, payload->data(), phys_length);
return { "OK" };
return {"OK"};
}
}
return { "E00" };
return {"E00"};
}
/// Remove hardware breakpoint.
static std::optional<std::string> Cmd$z1(const std::string_view& data)
static std::optional<std::string> Cmd$z1(std::string_view data)
{
auto address = StringUtil::FromChars<VirtualMemoryAddress>(data, 16);
if (address) {
if (address)
{
CPU::RemoveBreakpoint(CPU::BreakpointType::Execute, *address);
return { "OK" };
return {"OK"};
}
else {
else
{
return std::nullopt;
}
}
/// Insert hardware breakpoint.
static std::optional<std::string> Cmd$Z1(const std::string_view& data)
static std::optional<std::string> Cmd$Z1(std::string_view data)
{
auto address = StringUtil::FromChars<VirtualMemoryAddress>(data, 16);
if (address) {
if (address)
{
CPU::AddBreakpoint(CPU::BreakpointType::Execute, *address, false);
return { "OK" };
return {"OK"};
}
else {
else
{
return std::nullopt;
}
}
static std::optional<std::string> Cmd$vMustReplyEmpty(const std::string_view& data)
static std::optional<std::string> Cmd$vMustReplyEmpty(std::string_view data)
{
return { "" };
return {""};
}
static std::optional<std::string> Cmd$qSupported(const std::string_view& data)
static std::optional<std::string> Cmd$qSupported(std::string_view data)
{
return { "" };
return {""};
}
/// List of all GDB remote protocol packets supported by us.
static const std::map<const char*, std::function<std::optional<std::string>(const std::string_view&)>> COMMANDS
{
{ "?", Cmd$_questionMark },
{ "g", Cmd$g },
{ "G", Cmd$G },
{ "m", Cmd$m },
{ "M", Cmd$M },
{ "z0,", Cmd$z1 },
{ "Z0,", Cmd$Z1 },
{ "z1,", Cmd$z1 },
{ "Z1,", Cmd$Z1 },
{ "vMustReplyEmpty", Cmd$vMustReplyEmpty },
{ "qSupported", Cmd$qSupported },
static const std::map<const char*, std::function<std::optional<std::string>(std::string_view)>> COMMANDS{
{"?", Cmd$_questionMark},
{"g", Cmd$g},
{"G", Cmd$G},
{"m", Cmd$m},
{"M", Cmd$M},
{"z0,", Cmd$z1},
{"Z0,", Cmd$Z1},
{"z1,", Cmd$z1},
{"Z1,", Cmd$Z1},
{"vMustReplyEmpty", Cmd$vMustReplyEmpty},
{"qSupported", Cmd$qSupported},
};
bool IsPacketInterrupt(const std::string_view& data)
bool IsPacketInterrupt(std::string_view data)
{
return (data.size() >= 1) && (data[data.size()-1] == '\003');
return (data.size() >= 1) && (data[data.size() - 1] == '\003');
}
bool IsPacketContinue(const std::string_view& data)
bool IsPacketContinue(std::string_view data)
{
return (data.size() >= 5) && (data.substr(data.size()-5) == "$c#63");
return (data.size() >= 5) && (data.substr(data.size() - 5) == "$c#63");
}
bool IsPacketComplete(const std::string_view& data)
bool IsPacketComplete(std::string_view data)
{
return ((data.size() == 1) && (data[0] == '\003')) ||
((data.size() > 3) && (*(data.end()-3) == '#'));
return ((data.size() == 1) && (data[0] == '\003')) || ((data.size() > 3) && (*(data.end() - 3) == '#'));
}
std::string ProcessPacket(const std::string_view& data)
std::string ProcessPacket(std::string_view data)
{
std::string_view trimmedData = data;
// Eat ACKs.
while (!trimmedData.empty() && (trimmedData[0] == '+' || trimmedData[0] == '-')) {
if (trimmedData[0] == '-') {
while (!trimmedData.empty() && (trimmedData[0] == '+' || trimmedData[0] == '-'))
{
if (trimmedData[0] == '-')
{
Log_ErrorPrint("Received negative ack");
}
trimmedData = trimmedData.substr(1);
@@ -296,17 +315,20 @@ std::string ProcessPacket(const std::string_view& data)
// Validate packet.
auto packet = DeserializePacket(trimmedData);
if (!packet) {
if (!packet)
{
Log_ErrorPrintf("Malformed packet '%*s'", static_cast<int>(trimmedData.size()), trimmedData.data());
return "-";
}
std::optional<std::string> reply = { "" };
std::optional<std::string> reply = {""};
// Try to invoke packet command.
bool processed = false;
for (const auto& command : COMMANDS) {
if (packet->starts_with(command.first)) {
for (const auto& command : COMMANDS)
{
if (packet->starts_with(command.first))
{
Log_DebugPrintf("Processing command '%s'", command.first);
// Invoke command, remove command name from payload.
@@ -316,10 +338,11 @@ std::string ProcessPacket(const std::string_view& data)
}
}
if (!processed) {
if (!processed)
{
Log_WarningPrintf("Failed to process packet '%*s'", static_cast<int>(trimmedData.size()), trimmedData.data());
}
return reply ? "+"+SerializePacket(*reply) : "+";
return reply ? "+" + SerializePacket(*reply) : "+";
}
} // namespace GDBProtocol

View File

@@ -4,13 +4,10 @@
#pragma once
#include <string_view>
namespace GDBProtocol
{
bool IsPacketInterrupt(const std::string_view& data);
bool IsPacketContinue(const std::string_view& data);
bool IsPacketComplete(const std::string_view& data);
std::string ProcessPacket(const std::string_view& data);
namespace GDBProtocol {
bool IsPacketInterrupt(std::string_view data);
bool IsPacketContinue(std::string_view data);
bool IsPacketComplete(std::string_view data);
std::string ProcessPacket(std::string_view data);
} // namespace GDBProtocol

View File

@@ -74,7 +74,7 @@ SettingsInterface* GetSettingsInterface();
SettingsInterface* GetSettingsInterfaceForBindings();
/// Debugger feedback.
void ReportDebuggerMessage(const std::string_view& message);
void ReportDebuggerMessage(std::string_view message);
void ReportFormattedDebuggerMessage(const char* format, ...);
/// Returns a list of supported languages and codes (suffixes for translation files).

View File

@@ -329,8 +329,7 @@ bool MemoryCardImage::ReadFile(const DataArray& data, const FileInfo& fi, std::v
return true;
}
bool MemoryCardImage::WriteFile(DataArray* data, const std::string_view& filename, const std::vector<u8>& buffer,
Error* error)
bool MemoryCardImage::WriteFile(DataArray* data, std::string_view filename, const std::vector<u8>& buffer, Error* error)
{
if (buffer.empty())
{

View File

@@ -51,7 +51,7 @@ bool IsValid(const DataArray& data);
u32 GetFreeBlockCount(const DataArray& data);
std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted);
bool ReadFile(const DataArray& data, const FileInfo& fi, std::vector<u8>* buffer, Error* error);
bool WriteFile(DataArray* data, const std::string_view& filename, const std::vector<u8>& buffer, Error* error);
bool WriteFile(DataArray* data, std::string_view filename, const std::vector<u8>& buffer, Error* error);
bool DeleteFile(DataArray* data, const FileInfo& fi, bool clear_sectors);
bool UndeleteFile(DataArray* data, const FileInfo& fi);
bool ImportCard(DataArray* data, const char* filename, Error* error);

View File

@@ -1621,7 +1621,7 @@ std::string Settings::GetSharedMemoryCardPath(u32 slot) const
return ret;
}
std::string Settings::GetGameMemoryCardPath(const std::string_view& serial, u32 slot)
std::string Settings::GetGameMemoryCardPath(std::string_view serial, u32 slot)
{
return Path::Combine(EmuFolders::MemoryCards, fmt::format("{}_{}.mcd", serial, slot + 1));
}

View File

@@ -322,7 +322,7 @@ struct Settings
std::string GetSharedMemoryCardPath(u32 slot) const;
/// Returns the default path to a memory card for a specific game.
static std::string GetGameMemoryCardPath(const std::string_view& serial, u32 slot);
static std::string GetGameMemoryCardPath(std::string_view serial, u32 slot);
static void CPUOverclockPercentToFraction(u32 percent, u32* numerator, u32* denominator);
static u32 CPUOverclockFractionToPercent(u32 numerator, u32 denominator);

View File

@@ -540,18 +540,18 @@ u32 System::GetFrameTimeHistoryPos()
return s_frame_time_history_pos;
}
bool System::IsExeFileName(const std::string_view& path)
bool System::IsExeFileName(std::string_view path)
{
return (StringUtil::EndsWithNoCase(path, ".exe") || StringUtil::EndsWithNoCase(path, ".psexe") ||
StringUtil::EndsWithNoCase(path, ".ps-exe"));
}
bool System::IsPsfFileName(const std::string_view& path)
bool System::IsPsfFileName(std::string_view path)
{
return (StringUtil::EndsWithNoCase(path, ".psf") || StringUtil::EndsWithNoCase(path, ".minipsf"));
}
bool System::IsLoadableFilename(const std::string_view& path)
bool System::IsLoadableFilename(std::string_view path)
{
static constexpr const std::array extensions = {
".bin", ".cue", ".img", ".iso", ".chd", ".ecm", ".mds", // discs
@@ -570,7 +570,7 @@ bool System::IsLoadableFilename(const std::string_view& path)
return false;
}
bool System::IsSaveStateFilename(const std::string_view& path)
bool System::IsSaveStateFilename(std::string_view path)
{
return StringUtil::EndsWithNoCase(path, ".sav");
}
@@ -907,13 +907,13 @@ std::optional<DiscRegion> System::GetRegionForPath(const char* image_path)
return GetRegionForImage(cdi.get());
}
std::string System::GetGameSettingsPath(const std::string_view& game_serial)
std::string System::GetGameSettingsPath(std::string_view game_serial)
{
const std::string sanitized_serial(Path::SanitizeFileName(game_serial));
return Path::Combine(EmuFolders::GameSettings, fmt::format("{}.ini", sanitized_serial));
}
std::string System::GetInputProfilePath(const std::string_view& name)
std::string System::GetInputProfilePath(std::string_view name)
{
return Path::Combine(EmuFolders::InputProfiles, fmt::format("{}.ini", name));
}
@@ -3614,7 +3614,7 @@ u32 System::GetMediaSubImageIndex()
return cdi ? cdi->GetCurrentSubImage() : 0;
}
u32 System::GetMediaSubImageIndexForTitle(const std::string_view& title)
u32 System::GetMediaSubImageIndexForTitle(std::string_view title)
{
const CDImage* cdi = CDROM::GetMedia();
if (!cdi)
@@ -4533,7 +4533,7 @@ bool System::SaveScreenshot(const char* filename, DisplayScreenshotMode mode, Di
return g_gpu->RenderScreenshotToFile(filename, mode, quality, compress_on_thread, true);
}
std::string System::GetGameSaveStateFileName(const std::string_view& serial, s32 slot)
std::string System::GetGameSaveStateFileName(std::string_view serial, s32 slot)
{
if (slot < 0)
return Path::Combine(EmuFolders::SaveStates, fmt::format("{}_resume.sav", serial));

View File

@@ -112,16 +112,16 @@ using GameHash = u64;
extern TickCount g_ticks_per_second;
/// Returns true if the filename is a PlayStation executable we can inject.
bool IsExeFileName(const std::string_view& path);
bool IsExeFileName(std::string_view path);
/// Returns true if the filename is a Portable Sound Format file we can uncompress/load.
bool IsPsfFileName(const std::string_view& path);
bool IsPsfFileName(std::string_view path);
/// Returns true if the filename is one we can load.
bool IsLoadableFilename(const std::string_view& path);
bool IsLoadableFilename(std::string_view path);
/// Returns true if the filename is a save state.
bool IsSaveStateFilename(const std::string_view& path);
bool IsSaveStateFilename(std::string_view path);
/// Returns the preferred console type for a disc.
ConsoleRegion GetConsoleRegionForDiscRegion(DiscRegion region);
@@ -139,10 +139,10 @@ DiscRegion GetRegionForPsf(const char* path);
std::optional<DiscRegion> GetRegionForPath(const char* image_path);
/// Returns the path for the game settings ini file for the specified serial.
std::string GetGameSettingsPath(const std::string_view& game_serial);
std::string GetGameSettingsPath(std::string_view game_serial);
/// Returns the path for the input profile ini file with the specified name (may not exist).
std::string GetInputProfilePath(const std::string_view& name);
std::string GetInputProfilePath(std::string_view name);
State GetState();
void SetState(State new_state);
@@ -332,7 +332,7 @@ u32 GetMediaSubImageCount();
u32 GetMediaSubImageIndex();
/// Returns the index of the specified path in the playlist, or UINT32_MAX if it does not exist.
u32 GetMediaSubImageIndexForTitle(const std::string_view& title);
u32 GetMediaSubImageIndexForTitle(std::string_view title);
/// Returns the path to the specified playlist index.
std::string GetMediaSubImageTitle(u32 index);
@@ -374,7 +374,7 @@ void DoFrameStep();
void DoToggleCheats();
/// Returns the path to a save state file. Specifying an index of -1 is the "resume" save state.
std::string GetGameSaveStateFileName(const std::string_view& serial, s32 slot);
std::string GetGameSaveStateFileName(std::string_view serial, s32 slot);
/// Returns the path to a save state file. Specifying an index of -1 is the "resume" save state.
std::string GetGlobalSaveStateFileName(s32 slot);

View File

@@ -45,7 +45,7 @@ std::string TextureReplacementHash::ToString() const
return StringUtil::StdStringFromFormat("%" PRIx64 "%" PRIx64, high, low);
}
bool TextureReplacementHash::ParseString(const std::string_view& sv)
bool TextureReplacementHash::ParseString(std::string_view sv)
{
if (sv.length() != 32)
return false;

View File

@@ -20,7 +20,7 @@ struct TextureReplacementHash
u64 high;
std::string ToString() const;
bool ParseString(const std::string_view& sv);
bool ParseString(std::string_view sv);
bool operator<(const TextureReplacementHash& rhs) const { return std::tie(low, high) < std::tie(rhs.low, rhs.high); }
bool operator==(const TextureReplacementHash& rhs) const { return low == rhs.low && high == rhs.high; }