Skip to content

Commit 85ff8f3

Browse files
committed
Reduce code-duplication when caching data in CompiledFont.getPathJs
1 parent 234067e commit 85ff8f3

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/core/font_renderer.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -780,25 +780,22 @@ class CompiledFont {
780780

781781
getPathJs(unicode) {
782782
const { charCode, glyphId } = lookupCmap(this.cmap, unicode);
783-
let fn = this.compiledGlyphs[glyphId];
783+
let fn = this.compiledGlyphs[glyphId],
784+
compileEx;
784785
if (!fn) {
785786
try {
786-
fn = this.compiledGlyphs[glyphId] = this.compileGlyph(
787-
this.glyphs[glyphId],
788-
glyphId
789-
);
787+
fn = this.compileGlyph(this.glyphs[glyphId], glyphId);
790788
} catch (ex) {
791-
// Avoid attempting to re-compile a corrupt glyph.
792-
this.compiledGlyphs[glyphId] = NOOP;
789+
fn = NOOP; // Avoid attempting to re-compile a corrupt glyph.
793790

794-
if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
795-
this.compiledCharCodeToGlyphId[charCode] = glyphId;
796-
}
797-
throw ex;
791+
compileEx = ex;
798792
}
793+
this.compiledGlyphs[glyphId] = fn;
799794
}
800-
if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
801-
this.compiledCharCodeToGlyphId[charCode] = glyphId;
795+
this.compiledCharCodeToGlyphId[charCode] ??= glyphId;
796+
797+
if (compileEx) {
798+
throw compileEx;
802799
}
803800
return fn;
804801
}

0 commit comments

Comments
 (0)