1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #11373 from Snuffleupagus/fetch-cacheMap-rm-has

Slightly simplify the XRef cache lookup in `XRef.fetch`
This commit is contained in:
Tim van der Meij 2019-12-01 13:23:53 +01:00 committed by GitHub
commit ded56f2fe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1636,8 +1636,11 @@ var XRef = (function XRefClosure() {
}
const num = ref.num;
if (this._cacheMap.has(num)) {
const cacheEntry = this._cacheMap.get(num);
// The XRef cache is populated with objects which are obtained through
// `Parser.getObj`, and indirectly via `Lexer.getObj`. Neither of these
// methods should ever return `undefined` (note the `assert` calls below).
const cacheEntry = this._cacheMap.get(num);
if (cacheEntry !== undefined) {
// In documents with Object Streams, it's possible that cached `Dict`s
// have not been assigned an `objId` yet (see e.g. issue3115r.pdf).
if (cacheEntry instanceof Dict && !cacheEntry.objId) {
@ -1701,6 +1704,11 @@ var XRef = (function XRefClosure() {
xrefEntry = parser.getObj();
}
if (!isStream(xrefEntry)) {
if (typeof PDFJSDev === 'undefined' ||
PDFJSDev.test('!PRODUCTION || TESTING')) {
assert(xrefEntry !== undefined,
'fetchUncompressed: The "xrefEntry" cannot be undefined.');
}
this._cacheMap.set(num, xrefEntry);
}
return xrefEntry;
@ -1753,6 +1761,11 @@ var XRef = (function XRefClosure() {
}
const num = nums[i], entry = this.entries[num];
if (entry && entry.offset === tableOffset && entry.gen === i) {
if (typeof PDFJSDev === 'undefined' ||
PDFJSDev.test('!PRODUCTION || TESTING')) {
assert(obj !== undefined,
'fetchCompressed: The "obj" cannot be undefined.');
}
this._cacheMap.set(num, obj);
}
}