Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/core/primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,18 @@ class Dict {
}

class Ref {
constructor(num, gen) {
#str;

constructor(str, num, gen) {
this.#str = str;
this.num = num;
this.gen = gen;
}

toString() {
// This function is hot, so we make the string as compact as possible.
// |this.gen| is almost always zero, so we treat that case specially.
if (this.gen === 0) {
return `${this.num}R`;
}
return `${this.num}R${this.gen}`;
return this.#str;
}

static fromString(str) {
Expand All @@ -311,18 +311,16 @@ class Ref {
if (!m || m[1] === "0") {
return null;
}

const num = parseInt(m[1], 10),
gen = !m[2] ? 0 : parseInt(m[2], 10);
// eslint-disable-next-line no-restricted-syntax
return (RefCache[str] = new Ref(
parseInt(m[1], 10),
!m[2] ? 0 : parseInt(m[2], 10)
));
return (RefCache[str] = new Ref(str, num, gen));
}

static get(num, gen) {
const key = gen === 0 ? `${num}R` : `${num}R${gen}`;
const str = gen === 0 ? `${num}R` : `${num}R${gen}`;
// eslint-disable-next-line no-restricted-syntax
return (RefCache[key] ||= new Ref(num, gen));
return (RefCache[str] ||= new Ref(str, num, gen));
}
}

Expand Down
Loading