Manually hoist constant to avoid building it on each method invocation

This commit is contained in:
Chris Jones 2011-05-04 21:31:46 -05:00
parent a1faf7105f
commit 10c7ea0770

55
pdf.js
View File

@ -653,34 +653,6 @@ var Interpreter = (function() {
} }
const MAX_ARGS = 33; const MAX_ARGS = 33;
constructor.prototype = {
interpret: function(obj) {
return this.interpretHelper(new Parser(new Lexer(obj), true));
},
interpretHelper: function(parser) {
var args = [ ];
var obj;
while (!((obj = parser.getObj()).isEOF())) {
if (obj.isCmd()) {
this.dispatch(obj, args);
args = [ ]; // yuck
} else if (MAX_ARGS == args.length) {
this.error("Too many arguments");
} else {
args.push(obj);
}
}
},
dispatch: function(cmdObj, args) {
var fnName = this.getAndCheckCmd(cmdObj, args);
if (!(fnName in this.gfx))
this.error("Unimplemented function '"+ fnName +"'");
this.gfx[fnName].apply(this.gfx,
args.map(function(o) o.lowerToJS()));
},
getAndCheckCmd: function(cmdObj, args) {
const CMD_TABLE = { const CMD_TABLE = {
// Graphics state // Graphics state
"w" : { fn: "setLineWidth", "w" : { fn: "setLineWidth",
@ -733,6 +705,33 @@ var Interpreter = (function() {
// Compatibility // Compatibility
}; };
constructor.prototype = {
interpret: function(obj) {
return this.interpretHelper(new Parser(new Lexer(obj), true));
},
interpretHelper: function(parser) {
var args = [ ];
var obj;
while (!((obj = parser.getObj()).isEOF())) {
if (obj.isCmd()) {
this.dispatch(obj, args);
args = [ ]; // yuck
} else if (MAX_ARGS == args.length) {
this.error("Too many arguments");
} else {
args.push(obj);
}
}
},
dispatch: function(cmdObj, args) {
var fnName = this.getAndCheckCmd(cmdObj, args);
if (!(fnName in this.gfx))
this.error("Unimplemented function '"+ fnName +"'");
this.gfx[fnName].apply(this.gfx,
args.map(function(o) o.lowerToJS()));
},
getAndCheckCmd: function(cmdObj, args) {
var cmdName = cmdObj.value var cmdName = cmdObj.value
var cmd = CMD_TABLE[cmdName]; var cmd = CMD_TABLE[cmdName];
if (!cmd) { if (!cmd) {