Merge pull request #4982 from nnethercote/use-null-for-zero-args
Use null instead of [] for ops with no args.
This commit is contained in:
commit
3ad58db7e8
@ -653,7 +653,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var name = args[0].name;
|
var name = args[0].name;
|
||||||
if (imageCache.key === name) {
|
if (imageCache.key === name) {
|
||||||
operatorList.addOp(imageCache.fn, imageCache.args);
|
operatorList.addOp(imageCache.fn, imageCache.args);
|
||||||
args = [];
|
args = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -677,7 +677,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
} else if (type.name === 'Image') {
|
} else if (type.name === 'Image') {
|
||||||
self.buildPaintImageXObject(resources, xobj, false,
|
self.buildPaintImageXObject(resources, xobj, false,
|
||||||
operatorList, name, imageCache);
|
operatorList, name, imageCache);
|
||||||
args = [];
|
args = null;
|
||||||
continue;
|
continue;
|
||||||
} else if (type.name === 'PS') {
|
} else if (type.name === 'PS') {
|
||||||
// PostScript XObjects are unused when viewing documents.
|
// PostScript XObjects are unused when viewing documents.
|
||||||
@ -703,12 +703,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var cacheKey = args[0].cacheKey;
|
var cacheKey = args[0].cacheKey;
|
||||||
if (cacheKey && imageCache.key === cacheKey) {
|
if (cacheKey && imageCache.key === cacheKey) {
|
||||||
operatorList.addOp(imageCache.fn, imageCache.args);
|
operatorList.addOp(imageCache.fn, imageCache.args);
|
||||||
args = [];
|
args = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
self.buildPaintImageXObject(resources, args[0], true,
|
self.buildPaintImageXObject(resources, args[0], true,
|
||||||
operatorList, cacheKey, imageCache);
|
operatorList, cacheKey, imageCache);
|
||||||
args = [];
|
args = null;
|
||||||
continue;
|
continue;
|
||||||
case OPS.showText:
|
case OPS.showText:
|
||||||
args[0] = self.handleText(args[0], stateManager.state);
|
args[0] = self.handleText(args[0], stateManager.state);
|
||||||
@ -2099,7 +2099,9 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
read: function EvaluatorPreprocessor_read(operation) {
|
read: function EvaluatorPreprocessor_read(operation) {
|
||||||
var args = [];
|
// We use an array to represent args, except we use |null| to represent
|
||||||
|
// no args because it's more compact than an empty array.
|
||||||
|
var args = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
var obj = this.parser.getObj();
|
var obj = this.parser.getObj();
|
||||||
if (isEOF(obj)) {
|
if (isEOF(obj)) {
|
||||||
@ -2108,6 +2110,9 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||||||
if (!isCmd(obj)) {
|
if (!isCmd(obj)) {
|
||||||
// argument
|
// argument
|
||||||
if (obj !== null) {
|
if (obj !== null) {
|
||||||
|
if (!args) {
|
||||||
|
args = [];
|
||||||
|
}
|
||||||
args.push((obj instanceof Dict ? obj.getAll() : obj));
|
args.push((obj instanceof Dict ? obj.getAll() : obj));
|
||||||
assert(args.length <= 33, 'Too many arguments');
|
assert(args.length <= 33, 'Too many arguments');
|
||||||
}
|
}
|
||||||
@ -2127,28 +2132,34 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||||||
|
|
||||||
if (!opSpec.variableArgs) {
|
if (!opSpec.variableArgs) {
|
||||||
// Some post script commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
|
// Some post script commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
|
||||||
if (args.length !== numArgs) {
|
var argsLength = args !== null ? args.length : 0;
|
||||||
|
if (argsLength !== numArgs) {
|
||||||
var nonProcessedArgs = this.nonProcessedArgs;
|
var nonProcessedArgs = this.nonProcessedArgs;
|
||||||
while (args.length > numArgs) {
|
while (argsLength > numArgs) {
|
||||||
nonProcessedArgs.push(args.shift());
|
nonProcessedArgs.push(args.shift());
|
||||||
|
argsLength--;
|
||||||
}
|
}
|
||||||
while (args.length < numArgs && nonProcessedArgs.length !== 0) {
|
while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
|
||||||
|
if (!args) {
|
||||||
|
args = [];
|
||||||
|
}
|
||||||
args.unshift(nonProcessedArgs.pop());
|
args.unshift(nonProcessedArgs.pop());
|
||||||
|
argsLength++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length < numArgs) {
|
if (argsLength < numArgs) {
|
||||||
// If we receive too few args, it's not possible to possible
|
// If we receive too few args, it's not possible to possible
|
||||||
// to execute the command, so skip the command
|
// to execute the command, so skip the command
|
||||||
info('Command ' + fn + ': because expected ' +
|
info('Command ' + fn + ': because expected ' +
|
||||||
numArgs + ' args, but received ' + args.length +
|
numArgs + ' args, but received ' + argsLength +
|
||||||
' args; skipping');
|
' args; skipping');
|
||||||
args = [];
|
args = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (args.length > numArgs) {
|
} else if (argsLength > numArgs) {
|
||||||
info('Command ' + fn + ': expected [0,' + numArgs +
|
info('Command ' + fn + ': expected [0,' + numArgs +
|
||||||
'] args, but received ' + args.length + ' args');
|
'] args, but received ' + argsLength + ' args');
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO figure out how to type-check vararg functions
|
// TODO figure out how to type-check vararg functions
|
||||||
|
@ -57,7 +57,7 @@ describe('evaluator', function() {
|
|||||||
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
||||||
expect(result.fnArray.length).toEqual(1);
|
expect(result.fnArray.length).toEqual(1);
|
||||||
expect(result.fnArray[0]).toEqual(OPS.fill);
|
expect(result.fnArray[0]).toEqual(OPS.fill);
|
||||||
expect(result.argsArray[0].length).toEqual(0);
|
expect(result.argsArray[0]).toEqual(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ describe('evaluator', function() {
|
|||||||
expect(result.argsArray[0][0]).toEqual(true);
|
expect(result.argsArray[0][0]).toEqual(true);
|
||||||
expect(result.argsArray[1].length).toEqual(1);
|
expect(result.argsArray[1].length).toEqual(1);
|
||||||
expect(result.argsArray[1][0]).toEqual(false);
|
expect(result.argsArray[1][0]).toEqual(false);
|
||||||
expect(result.argsArray[2].length).toEqual(0);
|
expect(result.argsArray[2]).toEqual(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user