Optimize convertOpList
in svg.js
by computing the operator ID mapping only once
There is no need to recompute this for every operator list we encounter.
This commit is contained in:
parent
2b18e5a355
commit
5a03b1c0d7
@ -432,6 +432,14 @@ SVGGraphics = class SVGGraphics {
|
|||||||
this.embeddedFonts = Object.create(null);
|
this.embeddedFonts = Object.create(null);
|
||||||
this.cssStyle = null;
|
this.cssStyle = null;
|
||||||
this.forceDataSchema = !!forceDataSchema;
|
this.forceDataSchema = !!forceDataSchema;
|
||||||
|
|
||||||
|
// In `src/shared/util.js` the operator names are mapped to IDs.
|
||||||
|
// The list below represents the reverse of that, i.e., it maps IDs
|
||||||
|
// to operator names.
|
||||||
|
this._operatorIdMapping = [];
|
||||||
|
for (const op in OPS) {
|
||||||
|
this._operatorIdMapping[OPS[op]] = op;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
@ -493,11 +501,7 @@ SVGGraphics = class SVGGraphics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
convertOpList(operatorList) {
|
convertOpList(operatorList) {
|
||||||
const REVOPS = [];
|
const operatorIdMapping = this._operatorIdMapping;
|
||||||
for (const op in OPS) {
|
|
||||||
REVOPS[OPS[op]] = op;
|
|
||||||
}
|
|
||||||
|
|
||||||
const argsArray = operatorList.argsArray;
|
const argsArray = operatorList.argsArray;
|
||||||
const fnArray = operatorList.fnArray;
|
const fnArray = operatorList.fnArray;
|
||||||
const opList = [];
|
const opList = [];
|
||||||
@ -505,7 +509,7 @@ SVGGraphics = class SVGGraphics {
|
|||||||
const fnId = fnArray[i];
|
const fnId = fnArray[i];
|
||||||
opList.push({
|
opList.push({
|
||||||
'fnId': fnId,
|
'fnId': fnId,
|
||||||
'fn': REVOPS[fnId],
|
'fn': operatorIdMapping[fnId],
|
||||||
'args': argsArray[i],
|
'args': argsArray[i],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user