Cache label instructions for better performance
This commit is contained in:
@@ -173,6 +173,12 @@ class Executor {
|
|||||||
* @type {Object<string, Object<string, number>>}
|
* @type {Object<string, Object<string, number>>}
|
||||||
*/
|
*/
|
||||||
this.widths_ = {};
|
this.widths_ = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Object<string, Label>}
|
||||||
|
*/
|
||||||
|
this.labels_ = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,6 +189,10 @@ class Executor {
|
|||||||
* @return {Label} Label.
|
* @return {Label} Label.
|
||||||
*/
|
*/
|
||||||
createLabel(text, textKey, fillKey, strokeKey) {
|
createLabel(text, textKey, fillKey, strokeKey) {
|
||||||
|
const key = text + textKey + fillKey + strokeKey;
|
||||||
|
if (this.labels_[key]) {
|
||||||
|
return this.labels_[key];
|
||||||
|
}
|
||||||
const strokeState = strokeKey ? this.strokeStates[strokeKey] : null;
|
const strokeState = strokeKey ? this.strokeStates[strokeKey] : null;
|
||||||
const fillState = fillKey ? this.fillStates[fillKey] : null;
|
const fillState = fillKey ? this.fillStates[fillKey] : null;
|
||||||
const textState = this.textStates[textKey];
|
const textState = this.textStates[textKey];
|
||||||
@@ -239,6 +249,7 @@ class Executor {
|
|||||||
contextInstructions.push('fillText', [lines[i], x + leftRight * widths[i], 0.5 * (strokeWidth + lineHeight) + i * lineHeight]);
|
contextInstructions.push('fillText', [lines[i], x + leftRight * widths[i], 0.5 * (strokeWidth + lineHeight) + i * lineHeight]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.labels_[key] = label;
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user