From 4a9b1dae3db16efd52cecb875e70053e547b9b79 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Wed, 3 Nov 2021 18:19:39 +1100 Subject: [PATCH] stardict_lib: remove dead poGet{Current,Next,Pre}Word iterators They aren't used at all by scdv, and thus aren't tested (meaning that adaptions to the core lookup algorithms can be complicated because these methods use them but aren't tested so there's no real way of knowing if a change has broken the methods or not). Signed-off-by: Aleksa Sarai --- src/stardict_lib.cpp | 127 ------------------------------------------- src/stardict_lib.hpp | 3 - 2 files changed, 130 deletions(-) diff --git a/src/stardict_lib.cpp b/src/stardict_lib.cpp index bedf987..4202538 100644 --- a/src/stardict_lib.cpp +++ b/src/stardict_lib.cpp @@ -1037,133 +1037,6 @@ void Libs::load(const std::list &dicts_dirs, }); } -const gchar *Libs::poGetCurrentWord(glong *iCurrent) -{ - const gchar *poCurrentWord = nullptr; - const gchar *word; - for (std::vector::size_type iLib = 0; iLib < oLib.size(); iLib++) { - if (iCurrent[iLib] == INVALID_INDEX) - continue; - if (iCurrent[iLib] >= narticles(iLib) || iCurrent[iLib] < 0) - continue; - if (poCurrentWord == nullptr) { - poCurrentWord = poGetWord(iCurrent[iLib], iLib); - } else { - word = poGetWord(iCurrent[iLib], iLib); - - if (stardict_strcmp(poCurrentWord, word) > 0) - poCurrentWord = word; - } - } - return poCurrentWord; -} - -const gchar *Libs::poGetNextWord(const gchar *sWord, glong *iCurrent) -{ - // the input can be: - // (word,iCurrent),read word,write iNext to iCurrent,and return next word. used by TopWin::NextCallback(); - // (nullptr,iCurrent),read iCurrent,write iNext to iCurrent,and return next word. used by AppCore::ListWords(); - const gchar *poCurrentWord = nullptr; - size_t iCurrentLib = 0; - const gchar *word; - - glong nextWordIdx = 0; - std::set wordIndices; - - for (size_t iLib = 0; iLib < oLib.size(); ++iLib) { - wordIndices.clear(); - if (sWord) { - if (oLib[iLib]->Lookup(sWord, wordIndices, nextWordIdx)) { - // In order to progress over words which have multiple entries, - // pick the smallest index larger than iCurrent. - for (auto &wordIdx : wordIndices) { - if (wordIdx > iCurrent[iLib]) { - iCurrent[iLib] = wordIdx; - break; - } - } - } else { - iCurrent[iLib] = nextWordIdx; - } - } - if (iCurrent[iLib] == INVALID_INDEX) - continue; - if (iCurrent[iLib] >= narticles(iLib) || iCurrent[iLib] < 0) - continue; - if (poCurrentWord == nullptr) { - poCurrentWord = poGetWord(iCurrent[iLib], iLib); - iCurrentLib = iLib; - } else { - word = poGetWord(iCurrent[iLib], iLib); - - if (stardict_strcmp(poCurrentWord, word) > 0) { - poCurrentWord = word; - iCurrentLib = iLib; - } - } - } - if (poCurrentWord) { - iCurrent[iCurrentLib]++; - for (std::vector::size_type iLib = 0; iLib < oLib.size(); iLib++) { - if (iLib == iCurrentLib) - continue; - if (iCurrent[iLib] == INVALID_INDEX) - continue; - if (iCurrent[iLib] >= narticles(iLib) || iCurrent[iLib] < 0) - continue; - if (strcmp(poCurrentWord, poGetWord(iCurrent[iLib], iLib)) == 0) - iCurrent[iLib]++; - } - poCurrentWord = poGetCurrentWord(iCurrent); - } - return poCurrentWord; -} - -const gchar * -Libs::poGetPreWord(glong *iCurrent) -{ - // used by TopWin::PreviousCallback(); the iCurrent is cached by AppCore::TopWinWordChange(); - const gchar *poCurrentWord = nullptr; - std::vector::size_type iCurrentLib = 0; - const gchar *word; - - for (std::vector::size_type iLib = 0; iLib < oLib.size(); iLib++) { - if (iCurrent[iLib] == INVALID_INDEX) - iCurrent[iLib] = narticles(iLib); - else { - if (iCurrent[iLib] > narticles(iLib) || iCurrent[iLib] <= 0) - continue; - } - if (poCurrentWord == nullptr) { - poCurrentWord = poGetWord(iCurrent[iLib] - 1, iLib); - iCurrentLib = iLib; - } else { - word = poGetWord(iCurrent[iLib] - 1, iLib); - if (stardict_strcmp(poCurrentWord, word) < 0) { - poCurrentWord = word; - iCurrentLib = iLib; - } - } - } - - if (poCurrentWord) { - iCurrent[iCurrentLib]--; - for (std::vector::size_type iLib = 0; iLib < oLib.size(); iLib++) { - if (iLib == iCurrentLib) - continue; - if (iCurrent[iLib] > narticles(iLib) || iCurrent[iLib] <= 0) - continue; - if (strcmp(poCurrentWord, poGetWord(iCurrent[iLib] - 1, iLib)) == 0) { - iCurrent[iLib]--; - } else { - if (iCurrent[iLib] == narticles(iLib)) - iCurrent[iLib] = INVALID_INDEX; - } - } - } - return poCurrentWord; -} - bool Libs::LookupSimilarWord(const gchar *sWord, std::set &iWordIndices, int iLib) { bool bFound = false; diff --git a/src/stardict_lib.hpp b/src/stardict_lib.hpp index f864604..4161c4f 100644 --- a/src/stardict_lib.hpp +++ b/src/stardict_lib.hpp @@ -195,9 +195,6 @@ public: return nullptr; return oLib[iLib]->get_data(iIndex); } - const gchar *poGetCurrentWord(glong *iCurrent); - const gchar *poGetNextWord(const gchar *word, glong *iCurrent); - const gchar *poGetPreWord(glong *iCurrent); bool LookupWord(const gchar *sWord, std::set &iWordIndices, int iLib) { return oLib[iLib]->Lookup(sWord, iWordIndices);