Avoid OOM diring HTML parsing by reducing max block size and freeing unneeded buffers

This commit is contained in:
spfenwick
2026-05-02 16:07:27 +12:00
parent 913b7e5f8b
commit 5928f32364
2 changed files with 14 additions and 6 deletions
+8 -1
View File
@@ -355,12 +355,19 @@ void ParsedText::layoutAndExtractLines(
}
}
// Remove consumed words so size() reflects only remaining words
// Remove consumed words so size() reflects only remaining words, then
// release excess capacity. Without shrink_to_fit the vector retains a
// large allocation from before the flush; the next paragraph fills it
// back up and eventually needs an even larger contiguous realloc.
if (lineCount > 0) {
const size_t consumed = lineBreakIndices[lineCount - 1];
words.erase(words.begin(), words.begin() + consumed);
wordStyles.erase(wordStyles.begin(), wordStyles.begin() + consumed);
wordContinues.erase(wordContinues.begin(), wordContinues.begin() + consumed);
words.shrink_to_fit();
wordStyles.shrink_to_fit();
wordContinues.shrink_to_fit();
isContinuation_ = !includeLastLine;
}
}