From a74aaa636144586447bd4ccb2bcd981c6e194ed6 Mon Sep 17 00:00:00 2001 From: staticssleever668 <64694940+staticssleever668@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:16:09 +0300 Subject: [PATCH 01/10] DBProfile: catch exceptions by references Fixes exception messages always being unhelpful `std::exception`. --- src/Etterna/Models/Misc/DBProfile.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Etterna/Models/Misc/DBProfile.cpp b/src/Etterna/Models/Misc/DBProfile.cpp index c79c3f017a..9024d3f61a 100644 --- a/src/Etterna/Models/Misc/DBProfile.cpp +++ b/src/Etterna/Models/Misc/DBProfile.cpp @@ -34,7 +34,7 @@ DBProfile::LoadDBFromDir(std::string dir) // Open a database file db = new SQLite::Database(FILEMAN->ResolvePath(dir) + PROFILE_DB, SQLite::OPEN_READWRITE); - } catch (std::exception) { + } catch (std::exception&) { return ProfileLoadResult_FailedNoProfile; } try { @@ -46,7 +46,7 @@ DBProfile::LoadDBFromDir(std::string dir) LoadScoreGoals(db); LoadPlayLists(db); LoadPlayerScores(db); - } catch (std::exception) { + } catch (std::exception&) { return ProfileLoadResult_FailedTampered; } delete db; @@ -469,7 +469,7 @@ DBProfile::SaveDBToDir(string dir, // Open a database file db = new SQLite::Database(filename, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE); - } catch (std::exception) { + } catch (std::exception&) { return ProfileLoadResult_FailedNoProfile; } try { @@ -516,7 +516,7 @@ DBProfile::SaveDBToDir(string dir, db->exec("CREATE INDEX IF NOT EXISTS idx_songs " "ON songs(song, pack, id)"); transaction.commit(); - } catch (std::exception) { + } catch (std::exception&) { return ProfileLoadResult_FailedTampered; } delete db; @@ -1001,7 +1001,7 @@ DBProfile::SavePlayerScores(SQLite::Database* db, insertOffset.exec(); } } - } catch (std::exception) { // No replay data for + } catch (std::exception&) { // No replay data for // this score } hs->UnloadReplayData(); } @@ -1125,7 +1125,7 @@ DBProfile::WriteReplayData(const HighScore* hs) // Open a database file db = new SQLite::Database(filename, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE); - } catch (std::exception) { + } catch (std::exception&) { return ProfileLoadResult_FailedNoProfile; } try { @@ -1146,7 +1146,7 @@ DBProfile::WriteReplayData(const HighScore* hs) insertOffset.exec(); } transaction.commit(); - } catch (std::exception) { + } catch (std::exception&) { return ProfileLoadResult_FailedTampered != 0; } delete db; From ffe1b359e3dcdfb934e86cdc423de51d8f718d81 Mon Sep 17 00:00:00 2001 From: staticssleever668 <64694940+staticssleever668@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:16:37 +0300 Subject: [PATCH 02/10] NetworkSyncManager: catch exceptions by references --- src/Etterna/Singletons/NetworkSyncManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Etterna/Singletons/NetworkSyncManager.cpp b/src/Etterna/Singletons/NetworkSyncManager.cpp index 4c53b389b6..58943a77ed 100644 --- a/src/Etterna/Singletons/NetworkSyncManager.cpp +++ b/src/Etterna/Singletons/NetworkSyncManager.cpp @@ -1160,7 +1160,7 @@ ETTProtocol::Update(NetworkSyncManager* n, float fDeltaTime) std::string SMOnlineSelectScreen = THEME->GetMetric( "ScreenNetRoom", "MusicSelectScreen"); SCREENMAN->SetNewScreen(SMOnlineSelectScreen); - } catch (std::exception e) { + } catch (std::exception& e) { Locator::getLogger()->trace("Error while parsing ettp json enter " "room response: {}", e.what()); @@ -1310,7 +1310,7 @@ ETTProtocol::Update(NetworkSyncManager* n, float fDeltaTime) default: break; } - } catch (std::exception e) { + } catch (std::exception& e) { Locator::getLogger()->trace("Error while parsing ettp json message: {}", e.what()); } } From 90e3dca884e8eb96d5e0eec5b6fa586c802af636 Mon Sep 17 00:00:00 2001 From: staticssleever668 <64694940+staticssleever668@users.noreply.github.com> Date: Sun, 1 Aug 2021 14:59:25 +0300 Subject: [PATCH 03/10] SongCacheIndex: catch exceptions by references --- src/Etterna/Models/Songs/SongCacheIndex.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Etterna/Models/Songs/SongCacheIndex.cpp b/src/Etterna/Models/Songs/SongCacheIndex.cpp index e4ffd63d95..53a5a00d5c 100644 --- a/src/Etterna/Models/Songs/SongCacheIndex.cpp +++ b/src/Etterna/Models/Songs/SongCacheIndex.cpp @@ -271,7 +271,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } try { insertTimingData.exec(); - } catch (exception e) { + } catch (exception& e) { Locator::getLogger()->warn("Failed to execute statement to insert TimingData from Cache: {}", e.what()); } return sqlite3_last_insert_rowid(db->getHandle()); @@ -352,7 +352,7 @@ SongCacheIndex::InsertSteps(Steps* pSteps, int64_t songID) insertSteps.bind(stepsIndex++, static_cast(songID)); try { insertSteps.exec(); - } catch (exception e) { + } catch (exception& e) { Locator::getLogger()->warn("Failed to execute statement to insert Steps from Cache: {}", e.what()); } return sqlite3_last_insert_rowid(db->getHandle()); @@ -722,7 +722,7 @@ SongCacheIndex::~SongCacheIndex() if (curTransaction != nullptr) { try { curTransaction->commit(); - } catch (exception e) { + } catch (exception& e) { // DB transaction commit failed, we're destructing so we dont care. // There really shouldnt be a transaction left anyways } @@ -807,7 +807,7 @@ SongCacheIndex::LoadCache( ld->SetProgress(0); ld->SetTotalWork(count); } - } catch (exception e) { + } catch (exception& e) { Locator::getLogger()->warn("Failed to count all from songs table in Cache DB: {}", e.what()); } cache.reserve(count); @@ -898,7 +898,7 @@ SongCacheIndex::DeleteSongFromDBByCondition(string& condition) condition + ")") .c_str()); db->exec(("DELETE FROM songs WHERE " + condition).c_str()); - } catch (exception e) { + } catch (exception& e) { Locator::getLogger()->warn("Failed to execute Song Deletion from DB with condition " "'{}'\nException: {}", condition.c_str(), e.what()); } @@ -952,7 +952,7 @@ SongCacheIndex::StartTransaction() return; try { curTransaction = new SQLite::Transaction(*db); - } catch (exception e) { + } catch (exception& e) { Locator::getLogger()->warn("Failed to start transaction due to exception: {}", e.what()); } return; @@ -964,7 +964,7 @@ SongCacheIndex::FinishTransaction() return; try { curTransaction->commit(); - } catch (exception e) { + } catch (exception& e) { // DB transaction commit failed, we're destructing so we dont care. // There really shouldnt be a transaction left anyways } @@ -1329,7 +1329,7 @@ SongCacheIndex::SongFromStatement(Song* song, SQLite::Statement& query) static_cast(query.getColumn(index++)); song->m_sPreviewVidPath = static_cast(query.getColumn(index++)); - } catch (exception e) { + } catch (exception& e) { Locator::getLogger()->warn("Exception occurred while loading file from cache: {}", e.what()); } From 4cb8ede0c239b8d79e08ba11a1d79339125663df Mon Sep 17 00:00:00 2001 From: staticssleever668 <64694940+staticssleever668@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:23:29 +0300 Subject: [PATCH 04/10] SongCacheIndex: remove redundant string initializations --- src/Etterna/Models/Songs/SongCacheIndex.cpp | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Etterna/Models/Songs/SongCacheIndex.cpp b/src/Etterna/Models/Songs/SongCacheIndex.cpp index 53a5a00d5c..acdbf44e23 100644 --- a/src/Etterna/Models/Songs/SongCacheIndex.cpp +++ b/src/Etterna/Models/Songs/SongCacheIndex.cpp @@ -108,7 +108,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) insertTimingData.bind(timingDataIndex++, timing.m_fBeat0OffsetInSeconds); { auto const& segs = timing.GetTimingSegments(SEGMENT_BPM); - string bpms = ""; + string bpms; if (!segs.empty()) { for (auto&& seg : segs) { const BPMSegment* segment = ToBPM(seg); @@ -122,7 +122,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } { auto const& segs = timing.GetTimingSegments(SEGMENT_STOP); - string stops = ""; + string stops; if (!segs.empty()) { for (auto&& seg : segs) { const StopSegment* segment = ToStop(seg); @@ -137,7 +137,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } { auto const& segs = timing.GetTimingSegments(SEGMENT_DELAY); - string delays = ""; + string delays; if (!segs.empty()) { for (auto&& seg : segs) { const DelaySegment* segment = ToDelay(seg); @@ -152,7 +152,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } { auto const& segs = timing.GetTimingSegments(SEGMENT_WARP); - string warps = ""; + string warps; if (!segs.empty()) { for (auto&& seg : segs) { const WarpSegment* segment = ToWarp(seg); @@ -167,7 +167,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } { auto const& segs = timing.GetTimingSegments(SEGMENT_TIME_SIG); - string timesigs = ""; + string timesigs; if (!segs.empty()) { for (auto&& seg : segs) { const TimeSignatureSegment* segment = ToTimeSignature(seg); @@ -184,7 +184,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } { auto const& segs = timing.GetTimingSegments(SEGMENT_TICKCOUNT); - string ticks = ""; + string ticks; if (!segs.empty()) { for (auto&& seg : segs) { const TickcountSegment* segment = ToTickcount(seg); @@ -199,7 +199,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } { auto const& segs = timing.GetTimingSegments(SEGMENT_COMBO); - string combos = ""; + string combos; if (!segs.empty()) { for (auto&& seg : segs) { const ComboSegment* segment = ToCombo(seg); @@ -221,7 +221,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } { auto const& segs = timing.GetTimingSegments(SEGMENT_SPEED); - string speeds = ""; + string speeds; if (!segs.empty()) { for (auto&& seg : segs) { const SpeedSegment* segment = ToSpeed(seg); @@ -238,7 +238,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } { auto const& segs = timing.GetTimingSegments(SEGMENT_SCROLL); - string scrolls = ""; + string scrolls; if (!segs.empty()) { for (auto&& seg : segs) { const ScrollSegment* segment = ToScroll(seg); @@ -254,7 +254,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } { auto const& segs = timing.GetTimingSegments(SEGMENT_LABEL); - string labels = ""; + string labels; if (!segs.empty()) { for (auto&& seg : segs) { const LabelSegment* segment = ToLabel(seg); @@ -496,7 +496,7 @@ SongCacheIndex::CacheSong(Song& song, const std::string& dir) }; */ FOREACH_BackgroundLayer(b) { - string bgchanges = ""; + string bgchanges; if (song.GetBackgroundChanges(b).empty()) { insertSong.bind(index++); continue; // skip @@ -527,7 +527,7 @@ SongCacheIndex::CacheSong(Song& song, const std::string& dir) } if (!song.m_vsKeysoundFile.empty()) { - string keysounds = ""; + string keysounds; for (unsigned i = 0; i < song.m_vsKeysoundFile.size(); i++) { keysounds.append(song.m_vsKeysoundFile[i]); if (i != song.m_vsKeysoundFile.size() - 1) { From ae8e0cbbba88e4d5d70914e7d2503880f534338c Mon Sep 17 00:00:00 2001 From: staticssleever668 <64694940+staticssleever668@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:26:43 +0300 Subject: [PATCH 05/10] SongCacheIndex: make some functions constant --- src/Etterna/Models/Songs/SongCacheIndex.cpp | 21 ++++++++++----------- src/Etterna/Models/Songs/SongCacheIndex.h | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/Etterna/Models/Songs/SongCacheIndex.cpp b/src/Etterna/Models/Songs/SongCacheIndex.cpp index acdbf44e23..01c9f8d769 100644 --- a/src/Etterna/Models/Songs/SongCacheIndex.cpp +++ b/src/Etterna/Models/Songs/SongCacheIndex.cpp @@ -93,7 +93,7 @@ SongCacheIndex::SongCacheIndex() } int64_t -SongCacheIndex::InsertStepsTimingData(const TimingData& timing) +SongCacheIndex::InsertStepsTimingData(const TimingData& timing) const { SQLite::Statement insertTimingData(*db, "INSERT INTO timingdatas VALUES (NULL, " @@ -278,7 +278,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) } int64_t -SongCacheIndex::InsertSteps(Steps* pSteps, int64_t songID) +SongCacheIndex::InsertSteps(Steps* pSteps, int64_t songID) const { SQLite::Statement insertSteps(*db, "INSERT INTO steps VALUES (NULL, " @@ -359,7 +359,7 @@ SongCacheIndex::InsertSteps(Steps* pSteps, int64_t songID) } /* Save a song to the cache db*/ bool -SongCacheIndex::CacheSong(Song& song, const std::string& dir) +SongCacheIndex::CacheSong(Song& song, const std::string& dir) const { DeleteSongFromDBByDir(dir); try { @@ -611,7 +611,7 @@ SongCacheIndex::ResetDB() CreateDBTables(); } void -SongCacheIndex::CreateDBTables() +SongCacheIndex::CreateDBTables() const { try { db->exec("CREATE TABLE IF NOT EXISTS dbinfo (ID INTEGER PRIMARY KEY, " @@ -796,7 +796,7 @@ join(R1, A1...> const& outer) void SongCacheIndex::LoadCache( LoadingWindow* ld, - vector, Song*>*>& cache) + vector, Song*>*>& cache) const { auto count = 0; try { @@ -882,10 +882,9 @@ SongCacheIndex::LoadCache( for (auto& thread : threadpool) thread.join(); cache = join(cacheParts); - return; } void -SongCacheIndex::DeleteSongFromDBByCondition(string& condition) +SongCacheIndex::DeleteSongFromDBByCondition(string& condition) const { try { db->exec( @@ -904,20 +903,20 @@ SongCacheIndex::DeleteSongFromDBByCondition(string& condition) } } void -SongCacheIndex::DeleteSongFromDB(Song* songPtr) +SongCacheIndex::DeleteSongFromDB(Song* songPtr) const { auto cond = "dir = \"" + songPtr->GetSongDir() + "\" AND hash = \"" + to_string(GetHashForDirectory(songPtr->GetSongDir())) + "\""; DeleteSongFromDBByCondition(cond); } void -SongCacheIndex::DeleteSongFromDBByDir(string dir) +SongCacheIndex::DeleteSongFromDBByDir(string dir) const { auto cond = "dir=\"" + dir + "\""; DeleteSongFromDBByCondition(cond); } void -SongCacheIndex::DeleteSongFromDBByDirHash(unsigned int hash) +SongCacheIndex::DeleteSongFromDBByDirHash(unsigned int hash) const { auto cond = "hash=\"" + to_string(hash) + "\""; DeleteSongFromDBByCondition(cond); @@ -974,7 +973,7 @@ SongCacheIndex::FinishTransaction() } inline pair -SongCacheIndex::SongFromStatement(Song* song, SQLite::Statement& query) +SongCacheIndex::SongFromStatement(Song* song, SQLite::Statement& query) const { // SSC::StepsTagInfo reused_steps_info(&*song, &out, dir, true); SSCLoader loader; diff --git a/src/Etterna/Models/Songs/SongCacheIndex.h b/src/Etterna/Models/Songs/SongCacheIndex.h index 45bc8b9b64..2e37931147 100644 --- a/src/Etterna/Models/Songs/SongCacheIndex.h +++ b/src/Etterna/Models/Songs/SongCacheIndex.h @@ -19,7 +19,7 @@ class SongCacheIndex bool OpenDB(); void ResetDB(); void DeleteDB(); - void CreateDBTables(); + void CreateDBTables() const; bool DBEmpty{ true }; SQLite::Transaction* curTransaction{ nullptr }; @@ -29,26 +29,26 @@ class SongCacheIndex ~SongCacheIndex(); inline std::pair SongFromStatement( Song* song, - SQLite::Statement& query); + SQLite::Statement& query) const; void LoadHyperCache(LoadingWindow* ld, std::map& hyperCache); void LoadCache( LoadingWindow* ld, std::vector, Song*>*>& - cache); - void DeleteSongFromDBByCondition(std::string& condition); - void DeleteSongFromDB(Song* songPtr); - void DeleteSongFromDBByDir(std::string dir); - void DeleteSongFromDBByDirHash(unsigned int hash); + cache) const; + void DeleteSongFromDBByCondition(std::string& condition) const; + void DeleteSongFromDB(Song* songPtr) const; + void DeleteSongFromDBByDir(std::string dir) const; + void DeleteSongFromDBByDirHash(unsigned int hash) const; static std::string GetCacheFilePath(const std::string& sGroup, const std::string& sPath); unsigned GetCacheHash(const std::string& path) const; bool delay_save_cache; - int64_t InsertStepsTimingData(const TimingData& timing); - int64_t InsertSteps(Steps* pSteps, int64_t songID); + int64_t InsertStepsTimingData(const TimingData& timing) const; + int64_t InsertSteps(Steps* pSteps, int64_t songID) const; bool LoadSongFromCache(Song* song, std::string dir); - bool CacheSong(Song& song, const std::string& dir); + bool CacheSong(Song& song, const std::string& dir) const; void StartTransaction(); void FinishTransaction(); }; From 9a331c03e4ce7ad8c27bc2be30d5720f65561a1e Mon Sep 17 00:00:00 2001 From: staticssleever668 <64694940+staticssleever668@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:27:58 +0300 Subject: [PATCH 06/10] SongCacheIndex: fix some type problems --- src/Etterna/Models/Songs/SongCacheIndex.cpp | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Etterna/Models/Songs/SongCacheIndex.cpp b/src/Etterna/Models/Songs/SongCacheIndex.cpp index 01c9f8d769..441890b802 100644 --- a/src/Etterna/Models/Songs/SongCacheIndex.cpp +++ b/src/Etterna/Models/Songs/SongCacheIndex.cpp @@ -104,7 +104,7 @@ SongCacheIndex::InsertStepsTimingData(const TimingData& timing) const (NULL, " "OFFSET=?, BPMS=?, STOPS=?, " "DELAYS=?, WARPS=?, TIMESIGNATURESEGMENT=?, TICKCOUNTS=?, " "COMBOS=?, SPEEDS=?, SCROLLS=?, FAKES=?, LABELS=?)");*/ - unsigned int timingDataIndex = 1; + int timingDataIndex = 1; insertTimingData.bind(timingDataIndex++, timing.m_fBeat0OffsetInSeconds); { auto const& segs = timing.GetTimingSegments(SEGMENT_BPM); @@ -348,7 +348,7 @@ SongCacheIndex::InsertSteps(Steps* pSteps, int64_t songID) const auto serializednd = nd.SerializeNoteData2(td); insertSteps.bind(stepsIndex++, serializednd.data(), - serializednd.size() * sizeof(NoteInfo)); + static_cast(serializednd.size() * sizeof(NoteInfo))); insertSteps.bind(stepsIndex++, static_cast(songID)); try { insertSteps.exec(); @@ -380,7 +380,7 @@ SongCacheIndex::CacheSong(Song& song, const std::string& dir) const "?, ?, ?, ?, " "?, ?, ?, ?, " "?, ?)"); - unsigned int index = 1; + int index = 1; insertSong.bind(index++, STEPFILE_VERSION_NUMBER); insertSong.bind(index++, song.m_sMainTitle); insertSong.bind(index++, song.m_sSubTitle); @@ -541,8 +541,8 @@ SongCacheIndex::CacheSong(Song& song, const std::string& dir) const insertSong.bind(index++, song.GetFirstSecond()); insertSong.bind(index++, song.GetLastSecond()); insertSong.bind(index++, song.m_sSongFileName.c_str()); - insertSong.bind(index++, song.m_bHasMusic); - insertSong.bind(index++, song.m_bHasBanner); + insertSong.bind(index++, static_cast(song.m_bHasMusic)); + insertSong.bind(index++, static_cast(song.m_bHasBanner)); insertSong.bind(index++, song.m_fMusicLengthSeconds); insertSong.bind(index++, GetHashForDirectory(song.GetSongDir())); insertSong.bind(index++, song.GetSongDir()); @@ -812,7 +812,7 @@ SongCacheIndex::LoadCache( } cache.reserve(count); auto fivePercent = std::max(count / 100 * 5, 1); - const int threads = std::thread::hardware_concurrency(); + const unsigned int threads = std::thread::hardware_concurrency(); const auto limit = count / threads; ThreadData data; std::atomic abort(false); @@ -821,7 +821,8 @@ SongCacheIndex::LoadCache( int limit, int offset, vector, Song*>*>* cachePart) { - auto counter = 0, lastUpdate = 0; + auto counter = 0; + auto lastUpdate = 0; try { SQLite::Statement query(*SONGINDEX->db, "SELECT * FROM songs LIMIT " + @@ -978,7 +979,7 @@ SongCacheIndex::SongFromStatement(Song* song, SQLite::Statement& query) const // SSC::StepsTagInfo reused_steps_info(&*song, &out, dir, true); SSCLoader loader; string dir; - int dirhash; + int dirhash = 0; try { int songid = query.getColumn(0); @@ -1179,7 +1180,7 @@ SongCacheIndex::SongFromStatement(Song* song, SQLite::Statement& query) const split(radarValues, ",", values, true); RadarValues rv; rv.Zero(); - for (size_t i = 0; i < NUM_RadarCategory; ++i) + for (int i = 0; i < NUM_RadarCategory; ++i) rv[i] = StringToInt(values[i]); pNewNotes->SetCachedRadarValues(rv); pNewNotes->SetCredit( @@ -1286,9 +1287,9 @@ SongCacheIndex::SongFromStatement(Song* song, SQLite::Statement& query) const pNewNotes->SetMaxBPM(BPMmax); } pNewNotes->SetFirstSecond( - static_cast(qSteps.getColumn(stepsIndex++))); + static_cast(qSteps.getColumn(stepsIndex++).getDouble())); pNewNotes->SetLastSecond( - static_cast(qSteps.getColumn(stepsIndex++))); + static_cast(qSteps.getColumn(stepsIndex++).getDouble())); // pNewNotes->SetSMNoteData(""); pNewNotes->TidyUpData(); pNewNotes->SetFilename( From 3106e420da84c78c5ddebf58d07a2007fdbd4600 Mon Sep 17 00:00:00 2001 From: staticssleever668 <64694940+staticssleever668@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:28:36 +0300 Subject: [PATCH 07/10] SongCacheIndex: remove redundant returns at the ends of void functions --- src/Etterna/Models/Songs/SongCacheIndex.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Etterna/Models/Songs/SongCacheIndex.cpp b/src/Etterna/Models/Songs/SongCacheIndex.cpp index 441890b802..6cd8160f7d 100644 --- a/src/Etterna/Models/Songs/SongCacheIndex.cpp +++ b/src/Etterna/Models/Songs/SongCacheIndex.cpp @@ -602,7 +602,6 @@ SongCacheIndex::DeleteDB() curTransaction = nullptr; } } - return; } void SongCacheIndex::ResetDB() @@ -769,7 +768,6 @@ SongCacheIndex::LoadHyperCache(LoadingWindow* ld, ResetDB(); return; } - return; } template class R1, @@ -955,7 +953,6 @@ SongCacheIndex::StartTransaction() } catch (exception& e) { Locator::getLogger()->warn("Failed to start transaction due to exception: {}", e.what()); } - return; } void SongCacheIndex::FinishTransaction() @@ -970,7 +967,6 @@ SongCacheIndex::FinishTransaction() } delete curTransaction; curTransaction = nullptr; - return; } inline pair From 5bd4a3a07e1dc8ecfb931a08a41e5148d68a0524 Mon Sep 17 00:00:00 2001 From: staticssleever668 <64694940+staticssleever668@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:28:56 +0300 Subject: [PATCH 08/10] SongCacheIndex: remove redundant null-pointer check --- src/Etterna/Models/Songs/SongCacheIndex.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Etterna/Models/Songs/SongCacheIndex.cpp b/src/Etterna/Models/Songs/SongCacheIndex.cpp index 6cd8160f7d..e03e589d49 100644 --- a/src/Etterna/Models/Songs/SongCacheIndex.cpp +++ b/src/Etterna/Models/Songs/SongCacheIndex.cpp @@ -588,8 +588,7 @@ Must be open already */ void SongCacheIndex::DeleteDB() { - if (db != nullptr) - delete db; + delete db; FILEMAN->Remove(CACHE_DB); try { db = new SQLite::Database(FILEMAN->ResolvePath(CACHE_DB), From caeab365da9f57167e69de8d0759ac821c8ee0a3 Mon Sep 17 00:00:00 2001 From: staticssleever668 <64694940+staticssleever668@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:29:15 +0300 Subject: [PATCH 09/10] SongCacheIndex: do null-pointer checks explicitly --- src/Etterna/Models/Songs/SongCacheIndex.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Etterna/Models/Songs/SongCacheIndex.cpp b/src/Etterna/Models/Songs/SongCacheIndex.cpp index e03e589d49..8d590a4eb5 100644 --- a/src/Etterna/Models/Songs/SongCacheIndex.cpp +++ b/src/Etterna/Models/Songs/SongCacheIndex.cpp @@ -734,7 +734,7 @@ SongCacheIndex::LoadHyperCache(LoadingWindow* ld, map& hyperCache) { const int count = db->execAndGet("SELECT COUNT(*) FROM songs"); - if (ld && count > 0) { + if ((ld != nullptr) && count > 0) { ld->SetIndeterminate(false); ld->SetProgress(0); ld->SetTotalWork(count); @@ -754,7 +754,7 @@ SongCacheIndex::LoadHyperCache(LoadingWindow* ld, lastDir = lastDir.substr(0, lastDir.find_last_of('/')); // this is a song directory. Load a new song. progress++; - if (ld && progress % onePercent == 0) { + if ((ld != nullptr) && progress % onePercent == 0) { ld->SetProgress(progress); ld->SetText("Loading Cache\n" + lastDir); } @@ -872,7 +872,7 @@ SongCacheIndex::LoadCache( thread.join(); return; } - if (ld) { + if (ld != nullptr) { ld->SetProgress(data._progress); } data.setUpdated(false); From 9f321fd27e2140e3661c426270711e33c12a0cf0 Mon Sep 17 00:00:00 2001 From: staticssleever668 <64694940+staticssleever668@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:30:19 +0300 Subject: [PATCH 10/10] SongCacheIndex: pass strings by constant references --- src/Etterna/Models/Songs/SongCacheIndex.cpp | 6 +++--- src/Etterna/Models/Songs/SongCacheIndex.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Etterna/Models/Songs/SongCacheIndex.cpp b/src/Etterna/Models/Songs/SongCacheIndex.cpp index 8d590a4eb5..aa823f7235 100644 --- a/src/Etterna/Models/Songs/SongCacheIndex.cpp +++ b/src/Etterna/Models/Songs/SongCacheIndex.cpp @@ -882,7 +882,7 @@ SongCacheIndex::LoadCache( cache = join(cacheParts); } void -SongCacheIndex::DeleteSongFromDBByCondition(string& condition) const +SongCacheIndex::DeleteSongFromDBByCondition(const string& condition) const { try { db->exec( @@ -908,7 +908,7 @@ SongCacheIndex::DeleteSongFromDB(Song* songPtr) const DeleteSongFromDBByCondition(cond); } void -SongCacheIndex::DeleteSongFromDBByDir(string dir) const +SongCacheIndex::DeleteSongFromDBByDir(const string& dir) const { auto cond = "dir=\"" + dir + "\""; DeleteSongFromDBByCondition(cond); @@ -1344,7 +1344,7 @@ SongCacheIndex::SongFromStatement(Song* song, SQLite::Statement& query) const /* Load a song from Cache DB Returns true if it was loaded**/ bool -SongCacheIndex::LoadSongFromCache(Song* song, std::string dir) +SongCacheIndex::LoadSongFromCache(Song* song, const std::string& dir) { try { SQLite::Statement query( diff --git a/src/Etterna/Models/Songs/SongCacheIndex.h b/src/Etterna/Models/Songs/SongCacheIndex.h index 2e37931147..972f72c28f 100644 --- a/src/Etterna/Models/Songs/SongCacheIndex.h +++ b/src/Etterna/Models/Songs/SongCacheIndex.h @@ -36,9 +36,9 @@ class SongCacheIndex LoadingWindow* ld, std::vector, Song*>*>& cache) const; - void DeleteSongFromDBByCondition(std::string& condition) const; + void DeleteSongFromDBByCondition(const std::string& condition) const; void DeleteSongFromDB(Song* songPtr) const; - void DeleteSongFromDBByDir(std::string dir) const; + void DeleteSongFromDBByDir(const std::string& dir) const; void DeleteSongFromDBByDirHash(unsigned int hash) const; static std::string GetCacheFilePath(const std::string& sGroup, const std::string& sPath); @@ -47,7 +47,7 @@ class SongCacheIndex int64_t InsertStepsTimingData(const TimingData& timing) const; int64_t InsertSteps(Steps* pSteps, int64_t songID) const; - bool LoadSongFromCache(Song* song, std::string dir); + bool LoadSongFromCache(Song* song, const std::string& dir); bool CacheSong(Song& song, const std::string& dir) const; void StartTransaction(); void FinishTransaction();