Convert the pagesRefCache, on PDFLinkService, from an Object to a Map

This seems like a more appropriate data structure, and as part of these changes the property was also converted to a *private* one.
This commit is contained in:
Jonas Jenwald 2022-01-03 13:57:53 +01:00
parent fc31e1ba87
commit 00aa9811e6

View File

@ -103,6 +103,8 @@ function addLinkAttributes(link, { url, target, rel, enabled = true } = {}) {
* @implements {IPDFLinkService}
*/
class PDFLinkService {
#pagesRefCache = new Map();
/**
* @param {PDFLinkServiceOptions} options
*/
@ -122,14 +124,12 @@ class PDFLinkService {
this.pdfDocument = null;
this.pdfViewer = null;
this.pdfHistory = null;
this._pagesRefCache = null;
}
setDocument(pdfDocument, baseUrl = null) {
this.baseUrl = baseUrl;
this.pdfDocument = pdfDocument;
this._pagesRefCache = Object.create(null);
this.#pagesRefCache.clear();
}
setViewer(pdfViewer) {
@ -505,7 +505,7 @@ class PDFLinkService {
}
const refStr =
pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
this._pagesRefCache[refStr] = pageNum;
this.#pagesRefCache.set(refStr, pageNum);
}
/**
@ -517,7 +517,7 @@ class PDFLinkService {
}
const refStr =
pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
return this._pagesRefCache?.[refStr] || null;
return this.#pagesRefCache.get(refStr) || null;
}
/**