Convert the ChunkedStreamManager.promisesByRequest
property to a Map
Compared to regular `Object`s, `Map`s have a number of advantageous properties: Of particular importance in this case is the built-in iteration support, and that determining if the structure is empty is easy.
This commit is contained in:
parent
dda7a5d1b7
commit
159e13c4e4
@ -18,7 +18,6 @@ import {
|
||||
arrayByteLength,
|
||||
arraysToBytes,
|
||||
createPromiseCapability,
|
||||
isEmptyObj,
|
||||
} from "../shared/util.js";
|
||||
import { MissingDataException } from "./core_utils.js";
|
||||
|
||||
@ -321,7 +320,7 @@ class ChunkedStreamManager {
|
||||
|
||||
this._chunksNeededByRequest = new Map();
|
||||
this._requestsByChunk = new Map();
|
||||
this.promisesByRequest = Object.create(null);
|
||||
this._promisesByRequest = new Map();
|
||||
this.progressiveDataLength = 0;
|
||||
this.aborted = false;
|
||||
|
||||
@ -397,7 +396,7 @@ class ChunkedStreamManager {
|
||||
}
|
||||
|
||||
const capability = createPromiseCapability();
|
||||
this.promisesByRequest[requestId] = capability;
|
||||
this._promisesByRequest.set(requestId, capability);
|
||||
|
||||
const chunksToRequest = [];
|
||||
for (const chunk of chunksNeeded) {
|
||||
@ -564,8 +563,8 @@ class ChunkedStreamManager {
|
||||
}
|
||||
|
||||
for (const requestId of loadedRequests) {
|
||||
const capability = this.promisesByRequest[requestId];
|
||||
delete this.promisesByRequest[requestId];
|
||||
const capability = this._promisesByRequest.get(requestId);
|
||||
this._promisesByRequest.delete(requestId);
|
||||
capability.resolve();
|
||||
}
|
||||
|
||||
@ -592,8 +591,8 @@ class ChunkedStreamManager {
|
||||
if (this.pdfNetworkStream) {
|
||||
this.pdfNetworkStream.cancelAllRequests(reason);
|
||||
}
|
||||
for (const requestId in this.promisesByRequest) {
|
||||
this.promisesByRequest[requestId].reject(reason);
|
||||
for (const [, capability] of this._promisesByRequest) {
|
||||
capability.reject(reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user