I solved this by implementing a new helper method that simply checks for the presence of a specific book within a given module. This faster than doing the look-up based on a complete book list.
bool ModuleHelper::moduleHasBook(sword::SWModule* module, std::string bookCode) { bool hasBook; stringstream key; key << bookCode; key << " 1:1"; module->setKey(key.str().c_str()); hasBook = module->hasEntry(module->getKey()); return hasBook; } Having 18 modules installed locally … calling this method for all 18 modules takes between 20-30 ms on the JavaScript side … and that’s sufficient :-). Best regards, Tobias > Am 13.05.2021 um 11:33 schrieb Tobias Klein <cont...@tklein.info>: > > Hi all, > > I am wondering whether it is possible to optimize the performance for getting > a module’s book list. > > The function I am currently using looks like this: > > vector<string> bookList; > string currentBookName = ""; > VerseKey *vk = (VerseKey *)module->getKey(); > > for ((*vk) = TOP; !vk->popError(); vk->setBook(vk->getBook()+1)) { > if (module->hasEntry(vk)) { > currentBookName = vk->getOSISBookName(); > bookList.push_back(currentBookName); > } > } > > In my node-sword-interface JavaScript world the wrapped function returns in a > time between 10-15ms depending on the module. > > When calling this once for the currently used Bible module … that’s fine. > But I now have a use case where I need to retrieve the book lists of all > installed modules at once. In Ezra Bible App, the user has a possibility to > switch the Bible module for the currently opened text. > In the respective selection box I would like to disable all Bible modules > that do not contain the currently opened book. This could be the case for NT > only, OT only or other modules of that sort. > In order to implement this dynamic disabling/enabling logic I need the book > lists of all available SWORD modules at once. And suddenly we are looking at > 200+ ms for the above mentioned function executed for let’s say 15 modules. > > I am testing on a Mac mini to get performance figures for a lower end machine > … > > Now, having said all that … is there a way of optimizing the performance of > the function above? Or have I overlooked something and need to approach this > use case differently? > > Best regards, > Tobias > _______________________________________________ > sword-devel mailing list: sword-devel@crosswire.org > http://crosswire.org/mailman/listinfo/sword-devel > Instructions to unsubscribe/change your settings at above page
_______________________________________________ sword-devel mailing list: sword-devel@crosswire.org http://crosswire.org/mailman/listinfo/sword-devel Instructions to unsubscribe/change your settings at above page