Hi Troy,

Thanks once more for highlighting the code smells as you did! :)

In node-sword-interface, I have now implemented two new helper methods getBookChapterCount <https://github.com/ezra-project/node-sword-interface/blob/ba3a0347fbe9a19cec5bd3daac080c5325dc7393/src/sword_backend/module_helper.cpp#L92> and getChapterVerseCount. <https://github.com/ezra-project/node-sword-interface/blob/ba3a0347fbe9a19cec5bd3daac080c5325dc7393/src/sword_backend/module_helper.cpp#L113> These methods use the getChapterMax() and getVerseMax() functions from SWORD.

Based on my new helper methods, I then refactored my code in the frontend a bit and saw a decent performance improvement after that (saving 800ms on startup time when directly loading a book).

Best regards,
Tobias

On 11/18/20 7:53 AM, Tobias Klein wrote:
I am note sure I condone this behavior here :)  If you found a need to do something like this because you couldn't easily use the suggestions below, please let me know and maybe we can fix something or extend functionality to meet your needs.

If you ever want to know how many Books, Chapters, Verses, etc. are available in a reference system, these should serve that purpose:

VerseKey::getTestamentMax()

VerseKey::getBookMax(), once you set the testament

VerseKey::getChapterMax(), once you set the book

VerseKey::getVerseMax(), once you set the chapter

At the time when I wrote that function I didn't realize that I could use VerseKey to determine max values of chapters/chapter-verses per book.
Thanks! I may actually refactor my code now based on your hint.

To give you some context how I use this function ... in Ezra Project, this is currently used in three places.
1) NavigationPane => Getting the number of chapters for a book
2) I have a "verse range formatter", that needs the verse count per chapter to work correctly. 3) In my TagStatistics function I calculate percentages relative to the total number of verses in a book.

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

Reply via email to