Skip to content

Commit 8dc3715

Browse files
Snuffleupaguspull[bot]
authored andcommitted
Change the seenStyles object, in PartialEvaluator.getTextContent, to a Set
Given that what we actually want is only to keep track of the loadedFont-names, rather than storing any actual data, using an object isn't really necessary here. Furthermore, in the current code, we're also using `in` when checking if the data exists, which is generally less efficient than just checking for the value directly.
1 parent ebd33c2 commit 8dc3715

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/core/evaluator.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ class PartialEvaluator {
19741974
normalizeWhitespace = false,
19751975
combineTextItems = false,
19761976
sink,
1977-
seenStyles = Object.create(null),
1977+
seenStyles = new Set(),
19781978
}) {
19791979
// Ensure that `resources`/`stateManager` is correctly initialized,
19801980
// even if the provided parameter is e.g. `null`.
@@ -2024,17 +2024,19 @@ class PartialEvaluator {
20242024
if (textContentItem.initialized) {
20252025
return textContentItem;
20262026
}
2027-
var font = textState.font;
2028-
if (!(font.loadedName in seenStyles)) {
2029-
seenStyles[font.loadedName] = true;
2030-
textContent.styles[font.loadedName] = {
2027+
const font = textState.font,
2028+
loadedName = font.loadedName;
2029+
if (!seenStyles.has(loadedName)) {
2030+
seenStyles.add(loadedName);
2031+
2032+
textContent.styles[loadedName] = {
20312033
fontFamily: font.fallbackName,
20322034
ascent: font.ascent,
20332035
descent: font.descent,
20342036
vertical: font.vertical,
20352037
};
20362038
}
2037-
textContentItem.fontName = font.loadedName;
2039+
textContentItem.fontName = loadedName;
20382040

20392041
// 9.4.4 Text Space Details
20402042
var tsm = [

0 commit comments

Comments
 (0)