From 90b5fcb8e00e99c51d3e9d323fc37484c8bdeede Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 1 May 2021 12:17:46 +0200 Subject: [PATCH] Remove unnecessary TypedArray re-initialization in `FontFaceObject.createFontFaceRule` The `this.data` property is, when defined, sent from the worker-thread as a `Uint8Array` and there's thus no reason to re-initialize the TypedArray here. Note also the `FontFaceObject.createNativeFontFace` method just above, where we simply use `this.data` as-is. The explanation for this code looking like it does is, as is often the case, for historical reasons. Originally we only supported `@font-face`, before the Font Loading API existed, and back then we also polyfilled TypedArrays (using regular Arrays) which should explain this particular line of code. --- src/display/font_loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/display/font_loader.js b/src/display/font_loader.js index 619915ecc..fb1e78d3c 100644 --- a/src/display/font_loader.js +++ b/src/display/font_loader.js @@ -397,7 +397,7 @@ class FontFaceObject { if (!this.data || this.disableFontFace) { return null; } - const data = bytesToString(new Uint8Array(this.data)); + const data = bytesToString(this.data); // Add the @font-face rule to the document. const url = `url(data:${this.mimetype};base64,${btoa(data)});`; let rule;