Browse Source

Optimize Ref_toString().

I have a large PDF where this function is called 1.6 million times
during loading. Minimizing the string concatenations reduces the
cumulative allocations done by Firefox within this function from 113 MB
to 48 MB.
Nicholas Nethercote 11 years ago
parent
commit
856e1c600b
  1. 8
      src/core/obj.js

8
src/core/obj.js

@ -220,7 +220,13 @@ var Ref = (function RefClosure() { @@ -220,7 +220,13 @@ var Ref = (function RefClosure() {
Ref.prototype = {
toString: function Ref_toString() {
return 'R' + this.num + '.' + this.gen;
// 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.
var str = this.num + 'R';
if (this.gen !== 0) {
str += this.gen;
}
return str;
}
};

Loading…
Cancel
Save