From e0253a8664610d99b9bf3f512ac4fd7fe4f5800c Mon Sep 17 00:00:00 2001 From: hooligan333 <59103913+hooligan333@users.noreply.github.com> Date: Sat, 11 Jul 2026 19:24:43 -0700 Subject: [PATCH] perf: reserve CSS rule map before loading from cache (#2435) Co-authored-by: Erica Jensen --- lib/Epub/Epub/css/CssParser.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Epub/Epub/css/CssParser.cpp b/lib/Epub/Epub/css/CssParser.cpp index 3c30fd85..77ee8e77 100644 --- a/lib/Epub/Epub/css/CssParser.cpp +++ b/lib/Epub/Epub/css/CssParser.cpp @@ -803,6 +803,9 @@ bool CssParser::loadFromCache() { return false; } + // Size the bucket array up front to avoid incremental rehashes while loading rules. + rulesBySelector_.reserve(ruleCount); + auto hasRemainingBytes = [&file](const size_t neededBytes) -> bool { return static_cast(file.available()) >= neededBytes; };