Skip to content

Commit 024b3f3

Browse files
committed
perf(core): collecting a page's characters for fonts no longer copies the page into arrays
1 parent 6631d04 commit 024b3f3

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎packages/core/src/fonts/deterministicFonts.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,8 +1886,13 @@ function extractGoogleFontsText(html: string): string | undefined {
18861886
// Intentional over-approximation: raw html includes base64, scripts, and
18871887
// class names, but they collapse in the Set and the budget gate catches bloat.
18881888
const uniqueCharacters = new Set<string>();
1889-
for (const character of new Set([...Array.from(html), ...Array.from(decodedBodyText)])) {
1890-
addCaseClosure(uniqueCharacters, character, locales);
1889+
const seen = new Set<string>();
1890+
for (const text of [html, decodedBodyText]) {
1891+
for (const character of text) {
1892+
if (seen.has(character)) continue;
1893+
seen.add(character);
1894+
addCaseClosure(uniqueCharacters, character, locales);
1895+
}
18911896
}
18921897

18931898
if (hasTextTransformKeyword(html, FULL_WIDTH_KEYWORD_RE)) addFullwidthVariants(uniqueCharacters);

0 commit comments

Comments
 (0)