From 85ff8f34e22cc50de593e6bb7ec638356bc9e2a3 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 29 Apr 2024 12:37:32 +0200 Subject: [PATCH] Reduce code-duplication when caching data in `CompiledFont.getPathJs` --- src/core/font_renderer.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js index d5d1b1f2acfc0..5608e83d3e33c 100644 --- a/src/core/font_renderer.js +++ b/src/core/font_renderer.js @@ -780,25 +780,22 @@ class CompiledFont { getPathJs(unicode) { const { charCode, glyphId } = lookupCmap(this.cmap, unicode); - let fn = this.compiledGlyphs[glyphId]; + let fn = this.compiledGlyphs[glyphId], + compileEx; if (!fn) { try { - fn = this.compiledGlyphs[glyphId] = this.compileGlyph( - this.glyphs[glyphId], - glyphId - ); + fn = this.compileGlyph(this.glyphs[glyphId], glyphId); } catch (ex) { - // Avoid attempting to re-compile a corrupt glyph. - this.compiledGlyphs[glyphId] = NOOP; + fn = NOOP; // Avoid attempting to re-compile a corrupt glyph. - if (this.compiledCharCodeToGlyphId[charCode] === undefined) { - this.compiledCharCodeToGlyphId[charCode] = glyphId; - } - throw ex; + compileEx = ex; } + this.compiledGlyphs[glyphId] = fn; } - if (this.compiledCharCodeToGlyphId[charCode] === undefined) { - this.compiledCharCodeToGlyphId[charCode] = glyphId; + this.compiledCharCodeToGlyphId[charCode] ??= glyphId; + + if (compileEx) { + throw compileEx; } return fn; }