| 40 | } |
| 41 | |
| 42 | bool BookMetadataCache::beginTocPass() { |
| 43 | LOG_DBG("BMC", "Beginning toc pass"); |
| 44 | |
| 45 | if (!Storage.openFileForRead("BMC", cachePath + tmpSpineBinFile, spineFile)) { |
| 46 | return false; |
| 47 | } |
| 48 | if (!Storage.openFileForWrite("BMC", cachePath + tmpTocBinFile, tocFile)) { |
| 49 | // Explicit close() required: member variable persists beyond function scope |
| 50 | spineFile.close(); |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | if (spineCount >= LARGE_SPINE_THRESHOLD) { |
| 55 | spineHrefIndex.clear(); |
| 56 | spineHrefIndex.resize(spineCount); |
| 57 | spineFile.seek(0); |
| 58 | for (int i = 0; i < spineCount; i++) { |
| 59 | auto entry = readSpineEntry(spineFile); |
| 60 | SpineHrefIndexEntry idx; |
| 61 | idx.hrefHash = fnvHash64(entry.href); |
| 62 | idx.hrefLen = static_cast<uint16_t>(entry.href.size()); |
| 63 | idx.spineIndex = static_cast<int16_t>(i); |
| 64 | spineHrefIndex[i] = idx; |
| 65 | } |
| 66 | std::sort(spineHrefIndex.begin(), spineHrefIndex.end(), |
| 67 | [](const SpineHrefIndexEntry& a, const SpineHrefIndexEntry& b) { |
| 68 | return a.hrefHash < b.hrefHash || (a.hrefHash == b.hrefHash && a.hrefLen < b.hrefLen); |
| 69 | }); |
| 70 | spineFile.seek(0); |
| 71 | useSpineHrefIndex = true; |
| 72 | LOG_DBG("BMC", "Using fast index for %d spine items", spineCount); |
| 73 | } else { |
| 74 | useSpineHrefIndex = false; |
| 75 | } |
| 76 | |
| 77 | return true; |
| 78 | } |
| 79 | |
| 80 | bool BookMetadataCache::endTocPass() { |
| 81 | // Explicit close() required: member variables persist beyond function scope |
no test coverage detected