From bde62436faff534c31dd43ad6448cb70450cb2b1 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Sun, 26 Aug 2018 01:00:41 +0100 Subject: [PATCH] pcsx2: Simplify Game_Data member functions There's no need to have a lot of overloads accepting wxChar*, char* cand const wxString&. Keep only the const wxString& versions and remove the rest. This fixes an infinite recursion warning on FreeBSD. Also simplify sectionExists and getSection to avoid unnecessary conversion to and from wxString. --- pcsx2/GameDatabase.cpp | 4 ++-- pcsx2/GameDatabase.h | 46 +++++++++--------------------------------- 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/pcsx2/GameDatabase.cpp b/pcsx2/GameDatabase.cpp index 8abf7464ed..05a700a464 100644 --- a/pcsx2/GameDatabase.cpp +++ b/pcsx2/GameDatabase.cpp @@ -81,7 +81,7 @@ Game_Data* BaseGameDatabaseImpl::createNewGame( const wxString& id ) } // Searches the current game's data to see if the given key exists -bool Game_Data::keyExists(const wxChar* key) const { +bool Game_Data::keyExists(const wxString& key) const { for (auto it = kList.begin(); it != kList.end(); ++it) { if (it->CompareKey(key)) { return true; @@ -91,7 +91,7 @@ bool Game_Data::keyExists(const wxChar* key) const { } // Gets a string representation of the 'value' for the given key -wxString Game_Data::getString(const wxChar* key) const { +wxString Game_Data::getString(const wxString& key) const { for (auto it = kList.begin(); it != kList.end(); ++it) { if (it->CompareKey(key)) { return it->value; diff --git a/pcsx2/GameDatabase.h b/pcsx2/GameDatabase.h index 6d8d2db098..24cbc7ac54 100644 --- a/pcsx2/GameDatabase.h +++ b/pcsx2/GameDatabase.h @@ -84,65 +84,37 @@ struct Game_Data kList.clear(); } - bool keyExists(const wxChar* key) const; - wxString getString(const wxChar* key) const; + bool keyExists(const wxString& key) const; + wxString getString(const wxString& key) const; void writeString(const wxString& key, const wxString& value); bool IsOk() const { return !id.IsEmpty(); } - bool sectionExists(const wxChar* key, const wxString& value) const { - return keyExists(wxsFormat(L"[%s%s%s]", key, value.IsEmpty() ? L"" : L" = ", WX_STR(value))); + bool sectionExists(const wxString& key, const wxString& value) const { + return keyExists("[" + key + (value.empty() ? "" : " = ") + value + "]"); } - wxString getSection(const wxChar* key, const wxString& value) const { - return getString(wxsFormat(L"[%s%s%s]", key, value.IsEmpty() ? L"" : L" = ", WX_STR(value)).wx_str()); + wxString getSection(const wxString& key, const wxString& value) const { + return getString("[" + key + (value.empty() ? "" : " = ") + value + "]"); } // Gets an integer representation of the 'value' for the given key - int getInt(const wxChar* key) const { + int getInt(const wxString& key) const { unsigned long val; getString(key).ToULong(&val); return val; } // Gets a u8 representation of the 'value' for the given key - u8 getU8(const wxChar* key) const { + u8 getU8(const wxString& key) const { return (u8)wxAtoi(getString(key)); } // Gets a bool representation of the 'value' for the given key - bool getBool(const wxChar* key) const { - return !!wxAtoi(getString(key)); - } - - bool keyExists(const char* key) const { - return keyExists(fromUTF8(key).wx_str()); - } - - bool keyExists(const wxString& key) const { - return keyExists(key.wx_str()); - } - - wxString getString(const char* key) const { - return getString(fromUTF8(key).wx_str()); - } - - int getInt(const char* key) const { - return getInt(fromUTF8(key).wx_str()); - } - - u8 getU8(const char* key) const { - return getU8(fromUTF8(key).wx_str()); - } - - bool getBool(const char* key) const { - return getBool(fromUTF8(key).wx_str()); - } - bool getBool(const wxString& key) const { - return getBool(key.wx_str()); + return !!wxAtoi(getString(key)); } };