GameList: Use string_view for GetEntryForPath()

This commit is contained in:
Stenzek 2024-05-18 13:26:15 +10:00
parent 23598e6a42
commit 073ac87be2
No known key found for this signature in database
4 changed files with 18 additions and 16 deletions

View File

@ -2754,7 +2754,7 @@ void FullscreenUI::SwitchToGameSettings()
return;
auto lock = GameList::GetLock();
const GameList::Entry* entry = GameList::GetEntryForPath(System::GetDiscPath().c_str());
const GameList::Entry* entry = GameList::GetEntryForPath(System::GetDiscPath());
if (!entry)
{
SwitchToGameSettingsForSerial(System::GetGameSerial());
@ -2767,7 +2767,7 @@ void FullscreenUI::SwitchToGameSettings()
void FullscreenUI::SwitchToGameSettingsForPath(const std::string& path)
{
auto lock = GameList::GetLock();
const GameList::Entry* entry = GameList::GetEntryForPath(path.c_str());
const GameList::Entry* entry = GameList::GetEntryForPath(path);
if (entry)
SwitchToGameSettings(entry);
}
@ -5535,7 +5535,7 @@ u32 FullscreenUI::PopulateSaveStateListEntries(const std::string& title, const s
bool FullscreenUI::OpenLoadStateSelectorForGame(const std::string& game_path)
{
auto lock = GameList::GetLock();
const GameList::Entry* entry = GameList::GetEntryForPath(game_path.c_str());
const GameList::Entry* entry = GameList::GetEntryForPath(game_path);
if (entry)
{
s_save_state_selector_loading = true;
@ -6823,7 +6823,7 @@ GPUTexture* FullscreenUI::GetCoverForCurrentGame()
{
auto lock = GameList::GetLock();
const GameList::Entry* entry = GameList::GetEntryForPath(System::GetDiscPath().c_str());
const GameList::Entry* entry = GameList::GetEntryForPath(System::GetDiscPath());
if (!entry)
return s_fallback_disc_texture.get();

View File

@ -515,7 +515,7 @@ void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache,
}
std::unique_lock lock(s_mutex);
if (GetEntryForPath(ffd.FileName.c_str()) ||
if (GetEntryForPath(ffd.FileName) ||
AddFileFromCache(ffd.FileName, ffd.ModificationTime, played_time_map) || only_cache)
{
continue;
@ -590,13 +590,18 @@ const GameList::Entry* GameList::GetEntryByIndex(u32 index)
return (index < s_entries.size()) ? &s_entries[index] : nullptr;
}
const GameList::Entry* GameList::GetEntryForPath(const char* path)
const GameList::Entry* GameList::GetEntryForPath(std::string_view path)
{
const size_t path_length = std::strlen(path);
for (const Entry& entry : s_entries)
{
if (entry.path.size() == path_length && StringUtil::Strcasecmp(entry.path.c_str(), path) == 0)
// Use case-insensitive compare on Windows, since it's the same file.
#ifdef _WIN32
if (StringUtil::EqualNoCase(entry.path, path))
return &entry;
#else
if (entry.path == path)
return &entry;
#endif
}
return nullptr;
@ -606,11 +611,8 @@ const GameList::Entry* GameList::GetEntryBySerial(std::string_view serial)
{
for (const Entry& entry : s_entries)
{
if (entry.serial.length() == serial.length() &&
StringUtil::Strncasecmp(entry.serial.c_str(), serial.data(), serial.length()) == 0)
{
if (entry.serial == serial)
return &entry;
}
}
return nullptr;
@ -1191,7 +1193,7 @@ bool GameList::DownloadCovers(const std::vector<std::string>& url_templates, boo
// make sure it didn't get done already
{
std::unique_lock lock(s_mutex);
const GameList::Entry* entry = GetEntryForPath(entry_path.c_str());
const GameList::Entry* entry = GetEntryForPath(entry_path);
if (!entry || !GetCoverImagePathForEntry(entry).empty())
{
progress->IncrementProgressValue();
@ -1210,7 +1212,7 @@ bool GameList::DownloadCovers(const std::vector<std::string>& url_templates, boo
return;
std::unique_lock lock(s_mutex);
const GameList::Entry* entry = GetEntryForPath(entry_path.c_str());
const GameList::Entry* entry = GetEntryForPath(entry_path);
if (!entry || !GetCoverImagePathForEntry(entry).empty())
return;

View File

@ -77,7 +77,7 @@ bool PopulateEntryFromPath(const std::string& path, Entry* entry);
// Game list access. It's the caller's responsibility to hold the lock while manipulating the entry in any way.
std::unique_lock<std::recursive_mutex> GetLock();
const Entry* GetEntryByIndex(u32 index);
const Entry* GetEntryForPath(const char* path);
const Entry* GetEntryForPath(std::string_view path);
const Entry* GetEntryBySerial(std::string_view serial);
const Entry* GetEntryBySerialAndHash(std::string_view serial, u64 hash);
std::vector<const Entry*> GetDiscSetMembers(std::string_view disc_set_name);

View File

@ -140,7 +140,7 @@ void GameSummaryWidget::populateUi(const std::string& path, const std::string& s
{
auto lock = GameList::GetLock();
const GameList::Entry* gentry = GameList::GetEntryForPath(path.c_str());
const GameList::Entry* gentry = GameList::GetEntryForPath(path);
if (gentry)
m_ui.entryType->setCurrentIndex(static_cast<int>(gentry->type));
}