Skip to content

Commit

Permalink
Merge pull request #5219 from Snuffleupagus/sanitizeMetrics-avoid-int…
Browse files Browse the repository at this point in the history
…ermediate-strings

Avoid creating intermediate strings in sanitizeMetrics
  • Loading branch information
yurydelendik committed Aug 21, 2014
2 parents b4fb1e2 + ae896fc commit 4834f1c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 4834f1c

Please sign in to comment.