[Pkg-javascript-commits] [pdf.js] 06/204: Avoid creating intermediate strings in sanitizeMetrics
David Prévot
taffit at moszumanska.debian.org
Sat Oct 25 18:50:24 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit ae896fc07188147aaf26152a934d74ef715855d0
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date: Wed Aug 20 13:54:35 2014 +0200
Avoid creating intermediate strings in sanitizeMetrics
This patch avoids creating many intermediate strings, when adding dummy width/lsb entries for glyphs where those are missing.
For the relevant PDF files in our test suite, the average number of intermediate strings are well over 1000.
---
src/core/fonts.js | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/core/fonts.js b/src/core/fonts.js
index 4a7ad13..c30285f 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -3297,16 +3297,12 @@ var Font = (function FontClosure() {
var numMissing = numOfSidebearings -
((metrics.length - numOfMetrics * 4) >> 1);
- var i, ii;
if (numMissing > 0) {
- font.pos = (font.start ? font.start : 0) + metrics.offset;
- var entries = '';
- for (i = 0, ii = metrics.length; i < ii; i++) {
- entries += String.fromCharCode(font.getByte());
- }
- for (i = 0; i < numMissing; i++) {
- entries += '\x00\x00';
- }
+ // For each missing glyph, we set both the width and lsb to 0 (zero).
+ // Since we need to add two properties for each glyph, this explains
+ // the use of |numMissing * 2| when initializing the typed array.
+ var entries = new Uint8Array(metrics.length + numMissing * 2);
+ entries.set(metrics.data);
metrics.data = entries;
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list