mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
Optimize RAM usage: reduce parser buffers and use heap allocation
This commit is contained in:
parent
1374bc33ae
commit
71138a158d
@ -245,11 +245,11 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c
|
||||
viewportHeight, hyphenationEnabled);
|
||||
std::vector<uint32_t> lut = {};
|
||||
|
||||
ChapterHtmlSlimParser visitor(
|
||||
std::unique_ptr<ChapterHtmlSlimParser> visitor(new ChapterHtmlSlimParser(
|
||||
fileToParse, renderer, fontId, lineCompression, extraParagraphSpacing, paragraphAlignment, viewportWidth,
|
||||
viewportHeight, hyphenationEnabled,
|
||||
[this, &lut](std::unique_ptr<Page> page) { lut.emplace_back(this->onPageComplete(std::move(page))); },
|
||||
progressFn);
|
||||
progressFn));
|
||||
|
||||
Hyphenator::setPreferredLanguage(epub->getLanguage());
|
||||
|
||||
@ -257,7 +257,7 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c
|
||||
std::set<std::string> rewrittenInlineIds;
|
||||
int noterefCount = 0;
|
||||
|
||||
visitor.setNoterefCallback([this, ¬erefCount, &rewrittenInlineIds](Noteref& noteref) {
|
||||
visitor->setNoterefCallback([this, ¬erefCount, &rewrittenInlineIds](Noteref& noteref) {
|
||||
// Extract the ID from the href for tracking
|
||||
std::string href(noteref.href);
|
||||
|
||||
@ -277,7 +277,7 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c
|
||||
noterefCount++;
|
||||
});
|
||||
|
||||
success = visitor.parseAndBuildPages();
|
||||
success = visitor->parseAndBuildPages();
|
||||
|
||||
if (!isVirtual) {
|
||||
SdMan.remove(tmpHtmlPath.c_str());
|
||||
@ -293,9 +293,9 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c
|
||||
// --- Footnote Generation Logic (Merged from HEAD) ---
|
||||
|
||||
// Inline footnotes
|
||||
for (int i = 0; i < visitor.inlineFootnoteCount; i++) {
|
||||
const char* inlineId = visitor.inlineFootnotes[i].id;
|
||||
const char* inlineText = visitor.inlineFootnotes[i].text;
|
||||
for (int i = 0; i < visitor->inlineFootnoteCount; i++) {
|
||||
const char* inlineId = visitor->inlineFootnotes[i].id;
|
||||
const char* inlineText = visitor->inlineFootnotes[i].text;
|
||||
|
||||
if (rewrittenInlineIds.find(std::string(inlineId)) == rewrittenInlineIds.end()) continue;
|
||||
if (!inlineText || strlen(inlineText) == 0) continue;
|
||||
@ -326,9 +326,9 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c
|
||||
}
|
||||
|
||||
// Paragraph notes
|
||||
for (int i = 0; i < visitor.paragraphNoteCount; i++) {
|
||||
const char* pnoteId = visitor.paragraphNotes[i].id;
|
||||
const char* pnoteText = visitor.paragraphNotes[i].text;
|
||||
for (int i = 0; i < visitor->paragraphNoteCount; i++) {
|
||||
const char* pnoteId = visitor->paragraphNotes[i].id;
|
||||
const char* pnoteText = visitor->paragraphNotes[i].text;
|
||||
|
||||
if (!pnoteText || strlen(pnoteText) == 0) continue;
|
||||
if (rewrittenInlineIds.find(std::string(pnoteId)) == rewrittenInlineIds.end()) continue;
|
||||
|
||||
@ -90,12 +90,12 @@ class ChapterHtmlSlimParser {
|
||||
bool insideParagraphNote = false;
|
||||
int paragraphNoteDepth = 0;
|
||||
char currentParagraphNoteId[16] = {0};
|
||||
static constexpr int MAX_PNOTE_BUFFER = 512;
|
||||
static constexpr int MAX_PNOTE_BUFFER = 256;
|
||||
char currentParagraphNoteText[MAX_PNOTE_BUFFER] = {0};
|
||||
int currentParagraphNoteTextLen = 0;
|
||||
|
||||
// Temporary buffer for accumulation, will be copied to dynamic allocation
|
||||
static constexpr int MAX_ASIDE_BUFFER = 2048;
|
||||
static constexpr int MAX_ASIDE_BUFFER = 1024;
|
||||
char currentAsideText[MAX_ASIDE_BUFFER] = {0};
|
||||
int currentAsideTextLen = 0;
|
||||
|
||||
@ -116,7 +116,7 @@ class ChapterHtmlSlimParser {
|
||||
InlineFootnote inlineFootnotes[16];
|
||||
int inlineFootnoteCount = 0;
|
||||
// paragraph notes
|
||||
ParagraphNote paragraphNotes[32];
|
||||
ParagraphNote paragraphNotes[16];
|
||||
int paragraphNoteCount = 0;
|
||||
|
||||
explicit ChapterHtmlSlimParser(const std::string& filepath, GfxRenderer& renderer, const int fontId,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user