Pass the /Info-strings as a Map to the src/core/writer.js code

We want to iterate through the data in the `computeMD5` function, and `Map`s have "nicer" support for that than generic objects.
(Somewhat recently `Map` performance was improved in Firefox, however this also isn't really performance sensitive code.)
This commit is contained in:
Jonas Jenwald 2025-04-04 13:36:13 +02:00
parent 0bde69c7bf
commit dad6febc39
3 changed files with 8 additions and 8 deletions

View File

@ -674,12 +674,12 @@ class WorkerMessageHandler {
let newXrefInfo = Object.create(null); let newXrefInfo = Object.create(null);
if (xref.trailer) { if (xref.trailer) {
// Get string info from Info in order to compute fileId. // Get string info from Info in order to compute fileId.
const infoObj = Object.create(null); const infoMap = new Map();
const xrefInfo = xref.trailer.get("Info") || null; const xrefInfo = xref.trailer.get("Info") || null;
if (xrefInfo instanceof Dict) { if (xrefInfo instanceof Dict) {
for (const [key, value] of xrefInfo) { for (const [key, value] of xrefInfo) {
if (typeof value === "string") { if (typeof value === "string") {
infoObj[key] = stringToPDFString(value); infoMap.set(key, stringToPDFString(value));
} }
} }
} }
@ -689,7 +689,7 @@ class WorkerMessageHandler {
encryptRef: xref.trailer.getRaw("Encrypt") || null, encryptRef: xref.trailer.getRaw("Encrypt") || null,
newRef: xref.getNewTemporaryRef(), newRef: xref.getNewTemporaryRef(),
infoRef: xref.trailer.getRaw("Info") || null, infoRef: xref.trailer.getRaw("Info") || null,
info: infoObj, infoMap,
fileIds: xref.trailer.get("ID") || null, fileIds: xref.trailer.get("ID") || null,
startXRef: linearization startXRef: linearization
? startXRef ? startXRef

View File

@ -182,7 +182,7 @@ function computeMD5(filesize, xrefInfo) {
time.toString(), time.toString(),
filename, filename,
filesize.toString(), filesize.toString(),
...Object.values(xrefInfo.info), ...xrefInfo.infoMap.values(),
]; ];
const md5BufferLen = Math.sumPrecise(md5Buffer.map(str => str.length)); const md5BufferLen = Math.sumPrecise(md5Buffer.map(str => str.length));

View File

@ -42,7 +42,7 @@ describe("Writer", function () {
infoRef: null, infoRef: null,
encryptRef: null, encryptRef: null,
filename: "foo.pdf", filename: "foo.pdf",
info: {}, infoMap: new Map(),
}; };
let data = await incrementalUpdate({ let data = await incrementalUpdate({
@ -111,7 +111,7 @@ describe("Writer", function () {
infoRef: null, infoRef: null,
encryptRef: null, encryptRef: null,
filename: "foo.pdf", filename: "foo.pdf",
info: {}, infoMap: new Map(),
}; };
let data = await incrementalUpdate({ let data = await incrementalUpdate({
@ -218,7 +218,7 @@ describe("Writer", function () {
infoRef: null, infoRef: null,
encryptRef: null, encryptRef: null,
filename: "foo.pdf", filename: "foo.pdf",
info: {}, infoMap: new Map(),
}; };
let data = await incrementalUpdate({ let data = await incrementalUpdate({
@ -272,7 +272,7 @@ describe("Writer", function () {
infoRef: null, infoRef: null,
encryptRef: null, encryptRef: null,
filename: "foo.pdf", filename: "foo.pdf",
info: {}, infoMap: new Map(),
}; };
let data = await incrementalUpdate({ let data = await incrementalUpdate({