diff --git a/lib/Epub/Epub/BookMetadataCache.cpp b/lib/Epub/Epub/BookMetadataCache.cpp index 517d59d..98f86c1 100644 --- a/lib/Epub/Epub/BookMetadataCache.cpp +++ b/lib/Epub/Epub/BookMetadataCache.cpp @@ -49,23 +49,12 @@ bool BookMetadataCache::beginTocPass() { return false; } - // Build href->spineIndex lookup map for O(1) access during TOC creation - hrefToSpineIndex.clear(); - hrefToSpineIndex.reserve(spineCount); - spineFile.seek(0); - for (int i = 0; i < spineCount; i++) { - auto entry = readSpineEntry(spineFile); - hrefToSpineIndex[entry.href] = static_cast(i); - } - spineFile.seek(0); - return true; } bool BookMetadataCache::endTocPass() { tocFile.close(); spineFile.close(); - hrefToSpineIndex.clear(); return true; } @@ -271,10 +260,15 @@ void BookMetadataCache::createTocEntry(const std::string& title, const std::stri } int16_t spineIndex = -1; - auto it = hrefToSpineIndex.find(href); - if (it != hrefToSpineIndex.end()) { - spineIndex = it->second; - } else { + spineFile.seek(0); + for (int i = 0; i < spineCount; i++) { + auto spineEntry = readSpineEntry(spineFile); + if (spineEntry.href == href) { + spineIndex = static_cast(i); + break; + } + } + if (spineIndex == -1) { Serial.printf("[%lu] [BMC] addTocEntry: Could not find spine item for TOC href %s\n", millis(), href.c_str()); } diff --git a/lib/Epub/Epub/BookMetadataCache.h b/lib/Epub/Epub/BookMetadataCache.h index e0efc36..c7e9590 100644 --- a/lib/Epub/Epub/BookMetadataCache.h +++ b/lib/Epub/Epub/BookMetadataCache.h @@ -3,7 +3,6 @@ #include #include -#include #include class BookMetadataCache { @@ -55,8 +54,6 @@ class BookMetadataCache { // Temp file handles during build FsFile spineFile; FsFile tocFile; - // Lookup cache for O(1) href->spineIndex during TOC pass - std::unordered_map hrefToSpineIndex; uint32_t writeSpineEntry(FsFile& file, const SpineEntry& entry) const; uint32_t writeTocEntry(FsFile& file, const TocEntry& entry) const;