[Pkg-javascript-commits] [pdf.js] 118/207: Build up textChunk.str more efficiently.
David Prévot
taffit at moszumanska.debian.org
Mon Jul 28 15:36:38 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 bce760148081d955c227df9df72fdc34edf53886
Author: Nicholas Nethercote <nnethercote at mozilla.com>
Date: Wed Jun 18 06:59:52 2014 -0700
Build up textChunk.str more efficiently.
PartialEvaluator.getTextContent() builds up textChunk strings 1 char at a time,
creating many 100s of 1000s of intermediate strings along the way. This patch
make it instead push chars to an array and then join them at the end, as we
have done in numerous other places.
---
src/core/evaluator.js | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/core/evaluator.js b/src/core/evaluator.js
index be8900d..65365aa 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -908,7 +908,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
};
}
return {
- str: '',
+ // |str| is initially an array which we push individual chars to, and
+ // then runBidi() overwrites it with the final string.
+ str: [],
dir: null,
width: 0,
height: 0,
@@ -918,7 +920,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
function runBidi(textChunk) {
- var bidiResult = PDFJS.bidi(textChunk.str, -1, textState.font.vertical);
+ var str = textChunk.str.join('');
+ var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
textChunk.str = bidiResult.str;
textChunk.dir = bidiResult.dir;
return textChunk;
@@ -1008,7 +1011,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
textState.translateTextMatrix(tx, ty);
- textChunk.str += glyphUnicode;
+ textChunk.str.push(glyphUnicode);
}
var a = textState.textLineMatrix[0];
@@ -1103,10 +1106,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (fakeSpaces > MULTI_SPACE_FACTOR) {
fakeSpaces = Math.round(fakeSpaces);
while (fakeSpaces--) {
- textChunk.str += ' ';
+ textChunk.str.push(' ');
}
} else if (fakeSpaces > SPACE_FACTOR) {
- textChunk.str += ' ';
+ textChunk.str.push(' ');
}
}
}
--
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