1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Use a cache to minimize the number of Name objects.

This commit is contained in:
Nicholas Nethercote 2014-02-27 20:41:03 -08:00
parent cab5d7b96f
commit fdb7c218da
8 changed files with 18 additions and 14 deletions

View file

@ -548,7 +548,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
return userPassword;
}
var identityName = new Name('Identity');
var identityName = Name.get('Identity');
function CipherTransformFactory(dict, fileId, password) {
var filter = dict.get('Filter');

View file

@ -1102,7 +1102,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// FontDescriptor is only required for Type3 fonts when the document
// is a tagged pdf. Create a barbebones one to get by.
descriptor = new Dict();
descriptor.set('FontName', new Name(type.name));
descriptor.set('FontName', Name.get(type.name));
} else {
// Before PDF 1.5 if the font was one of the base 14 fonts, having a
// FontDescriptor was not required.
@ -1150,10 +1150,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var baseFont = dict.get('BaseFont');
// Some bad pdf's have a string as the font name.
if (isString(fontName)) {
fontName = new Name(fontName);
fontName = Name.get(fontName);
}
if (isString(baseFont)) {
baseFont = new Name(baseFont);
baseFont = Name.get(baseFont);
}
if (type.name !== 'Type3') {

View file

@ -88,7 +88,7 @@ var PDFImage = (function PDFImageClosure() {
var colorSpace = dict.get('ColorSpace', 'CS');
if (!colorSpace) {
warn('JPX images (which don"t require color spaces');
colorSpace = new Name('DeviceRGB');
colorSpace = Name.get('DeviceRGB');
}
this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
this.numComps = this.colorSpace.numComps;

View file

@ -30,6 +30,13 @@ var Name = (function NameClosure() {
Name.prototype = {};
var nameCache = {};
Name.get = function Name_get(name) {
var nameValue = nameCache[name];
return nameValue ? nameValue : (nameCache[name] = new Name(name));
};
return Name;
})();
@ -44,10 +51,7 @@ var Cmd = (function CmdClosure() {
Cmd.get = function Cmd_get(cmd) {
var cmdValue = cmdCache[cmd];
if (cmdValue)
return cmdValue;
return cmdCache[cmd] = new Cmd(cmd);
return cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd));
};
return Cmd;

View file

@ -586,7 +586,7 @@ var Lexer = (function LexerClosure() {
error('Warning: name token is longer than allowed by the spec: ' +
strBuf.length);
}
return new Name(strBuf.join(''));
return Name.get(strBuf.join(''));
},
getHexString: function Lexer_getHexString() {
var strBuf = this.strBuf;