Manually hoist constant to avoid building it on each method invocation
This commit is contained in:
parent
a1faf7105f
commit
10c7ea0770
55
pdf.js
55
pdf.js
@ -653,34 +653,6 @@ var Interpreter = (function() {
|
||||
}
|
||||
|
||||
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 = {
|
||||
// Graphics state
|
||||
"w" : { fn: "setLineWidth",
|
||||
@ -733,6 +705,33 @@ var Interpreter = (function() {
|
||||
// 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 cmd = CMD_TABLE[cmdName];
|
||||
if (!cmd) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user