Merge pull request #13179 from Snuffleupagus/more-Set

Utilize `Set` a bit more in the code-base
This commit is contained in:
Tim van der Meij 2021-04-05 14:06:53 +02:00 committed by GitHub
commit 11f2eab4b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 26 deletions

View File

@ -1974,7 +1974,7 @@ class PartialEvaluator {
normalizeWhitespace = false, normalizeWhitespace = false,
combineTextItems = false, combineTextItems = false,
sink, sink,
seenStyles = Object.create(null), seenStyles = new Set(),
}) { }) {
// Ensure that `resources`/`stateManager` is correctly initialized, // Ensure that `resources`/`stateManager` is correctly initialized,
// even if the provided parameter is e.g. `null`. // even if the provided parameter is e.g. `null`.
@ -2024,17 +2024,19 @@ class PartialEvaluator {
if (textContentItem.initialized) { if (textContentItem.initialized) {
return textContentItem; return textContentItem;
} }
var font = textState.font; const font = textState.font,
if (!(font.loadedName in seenStyles)) { loadedName = font.loadedName;
seenStyles[font.loadedName] = true; if (!seenStyles.has(loadedName)) {
textContent.styles[font.loadedName] = { seenStyles.add(loadedName);
textContent.styles[loadedName] = {
fontFamily: font.fallbackName, fontFamily: font.fallbackName,
ascent: font.ascent, ascent: font.ascent,
descent: font.descent, descent: font.descent,
vertical: font.vertical, vertical: font.vertical,
}; };
} }
textContentItem.fontName = font.loadedName; textContentItem.fontName = loadedName;
// 9.4.4 Text Space Details // 9.4.4 Text Space Details
var tsm = [ var tsm = [

View File

@ -1284,10 +1284,7 @@ class PDFPageProxy {
} }
const complete = error => { const complete = error => {
const i = intentState.renderTasks.indexOf(internalRenderTask); intentState.renderTasks.delete(internalRenderTask);
if (i >= 0) {
intentState.renderTasks.splice(i, 1);
}
// Attempt to reduce memory usage during *printing*, by always running // Attempt to reduce memory usage during *printing*, by always running
// cleanup once rendering has finished (regardless of cleanupAfterRender). // cleanup once rendering has finished (regardless of cleanupAfterRender).
@ -1332,10 +1329,7 @@ class PDFPageProxy {
pdfBug: this._pdfBug, pdfBug: this._pdfBug,
}); });
if (!intentState.renderTasks) { (intentState.renderTasks ||= new Set()).add(internalRenderTask);
intentState.renderTasks = [];
}
intentState.renderTasks.push(internalRenderTask);
const renderTask = internalRenderTask.task; const renderTask = internalRenderTask.task;
Promise.all([ Promise.all([
@ -1370,10 +1364,7 @@ class PDFPageProxy {
if (intentState.operatorList.lastChunk) { if (intentState.operatorList.lastChunk) {
intentState.opListReadCapability.resolve(intentState.operatorList); intentState.opListReadCapability.resolve(intentState.operatorList);
const i = intentState.renderTasks.indexOf(opListTask); intentState.renderTasks.delete(opListTask);
if (i >= 0) {
intentState.renderTasks.splice(i, 1);
}
} }
} }
@ -1389,8 +1380,7 @@ class PDFPageProxy {
opListTask = Object.create(null); opListTask = Object.create(null);
opListTask.operatorListChanged = operatorListChanged; opListTask.operatorListChanged = operatorListChanged;
intentState.opListReadCapability = createPromiseCapability(); intentState.opListReadCapability = createPromiseCapability();
intentState.renderTasks = []; (intentState.renderTasks ||= new Set()).add(opListTask);
intentState.renderTasks.push(opListTask);
intentState.operatorList = { intentState.operatorList = {
fnArray: [], fnArray: [],
argsArray: [], argsArray: [],
@ -1518,7 +1508,7 @@ class PDFPageProxy {
return false; return false;
} }
for (const { renderTasks, operatorList } of this._intentStates.values()) { for (const { renderTasks, operatorList } of this._intentStates.values()) {
if (renderTasks.length !== 0 || !operatorList.lastChunk) { if (renderTasks.size > 0 || !operatorList.lastChunk) {
return false; return false;
} }
} }
@ -1565,8 +1555,8 @@ class PDFPageProxy {
intentState.operatorList.lastChunk = operatorListChunk.lastChunk; intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
// Notify all the rendering tasks there are more operators to be consumed. // Notify all the rendering tasks there are more operators to be consumed.
for (let i = 0; i < intentState.renderTasks.length; i++) { for (const internalRenderTask of intentState.renderTasks) {
intentState.renderTasks[i].operatorListChanged(); internalRenderTask.operatorListChanged();
} }
if (operatorListChunk.lastChunk) { if (operatorListChunk.lastChunk) {
@ -1615,8 +1605,8 @@ class PDFPageProxy {
// Mark operator list as complete. // Mark operator list as complete.
intentState.operatorList.lastChunk = true; intentState.operatorList.lastChunk = true;
for (let i = 0; i < intentState.renderTasks.length; i++) { for (const internalRenderTask of intentState.renderTasks) {
intentState.renderTasks[i].operatorListChanged(); internalRenderTask.operatorListChanged();
} }
this._tryCleanup(); this._tryCleanup();
} }
@ -1650,7 +1640,7 @@ class PDFPageProxy {
if (!force) { if (!force) {
// Ensure that an Error occurring in *only* one `InternalRenderTask`, e.g. // Ensure that an Error occurring in *only* one `InternalRenderTask`, e.g.
// multiple render() calls on the same canvas, won't break all rendering. // multiple render() calls on the same canvas, won't break all rendering.
if (intentState.renderTasks.length !== 0) { if (intentState.renderTasks.size > 0) {
return; return;
} }
// Don't immediately abort parsing on the worker-thread when rendering is // Don't immediately abort parsing on the worker-thread when rendering is