MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / beginTocPass

Method beginTocPass

lib/Epub/Epub/BookMetadataCache.cpp:42–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42bool 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
80bool BookMetadataCache::endTocPass() {
81 // Explicit close() required: member variables persist beyond function scope

Callers 1

loadMethod · 0.80

Calls 8

openFileForReadMethod · 0.80
openFileForWriteMethod · 0.80
seekMethod · 0.80
endMethod · 0.80
closeMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected