Skip to content

Commit dcbb23d

Browse files
committed
Re-factor FontFaceObject.getPathGenerator to use Arrays instead of strings
This is similar to a lot of other code, where we use "Array + join" rather than repeated string concatenation.
1 parent 3538ef0 commit dcbb23d

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/display/font_loader.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ class FontFaceObject {
422422
return this.compiledGlyphs[character];
423423
}
424424

425-
let cmds, current;
425+
let cmds;
426426
try {
427427
cmds = objs.get(this.loadedName + "_path_" + character);
428428
} catch (ex) {
@@ -441,27 +441,22 @@ class FontFaceObject {
441441

442442
// If we can, compile cmds into JS for MAXIMUM SPEED...
443443
if (this.isEvalSupported && IsEvalSupportedCached.value) {
444-
let args,
445-
js = "";
446-
for (let i = 0, ii = cmds.length; i < ii; i++) {
447-
current = cmds[i];
448-
449-
if (current.args !== undefined) {
450-
args = current.args.join(",");
451-
} else {
452-
args = "";
453-
}
454-
js += "c." + current.cmd + "(" + args + ");\n";
444+
const jsBuf = [];
445+
for (const current of cmds) {
446+
const args = current.args !== undefined ? current.args.join(",") : "";
447+
jsBuf.push("c.", current.cmd, "(", args, ");\n");
455448
}
456449
// eslint-disable-next-line no-new-func
457-
return (this.compiledGlyphs[character] = new Function("c", "size", js));
450+
return (this.compiledGlyphs[character] = new Function(
451+
"c",
452+
"size",
453+
jsBuf.join("")
454+
));
458455
}
459456
// ... but fall back on using Function.prototype.apply() if we're
460457
// blocked from using eval() for whatever reason (like CSP policies).
461458
return (this.compiledGlyphs[character] = function (c, size) {
462-
for (let i = 0, ii = cmds.length; i < ii; i++) {
463-
current = cmds[i];
464-
459+
for (const current of cmds) {
465460
if (current.cmd === "scale") {
466461
current.args = [size, -size];
467462
}

0 commit comments

Comments
 (0)