[Pkg-javascript-commits] [pdf.js] 116/207: Add ChunkedStream.ensureByte().
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 4428cebdbccb00ddc5fe1a3ccd2bdf25fe2b006c
Author: Nicholas Nethercote <nnethercote at mozilla.com>
Date: Tue Jun 17 21:20:58 2014 -0700
Add ChunkedStream.ensureByte().
This new function is much faster than ensureRange(pos, pos+1), which is a very
common case.
This speeds up the rendering of some test cases (including the Tracemonkey
paper) by 4--5%.
---
src/core/chunked_stream.js | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js
index 8e40217..cf0e6b7 100644
--- a/src/core/chunked_stream.js
+++ b/src/core/chunked_stream.js
@@ -31,6 +31,7 @@ var ChunkedStream = (function ChunkedStreamClosure() {
this.numChunks = Math.ceil(length / chunkSize);
this.manager = manager;
this.initialDataLength = 0;
+ this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
}
// required methods for a stream. if a particular stream does not
@@ -90,6 +91,18 @@ var ChunkedStream = (function ChunkedStreamClosure() {
}
},
+ ensureByte: function ChunkedStream_ensureRange(pos) {
+ var chunk = Math.floor(pos / this.chunkSize);
+ if (chunk === this.lastSuccessfulEnsureByteChunk) {
+ return;
+ }
+
+ if (!(chunk in this.loadedChunks)) {
+ throw new MissingDataException(pos, pos + 1);
+ }
+ this.lastSuccessfulEnsureByteChunk = chunk;
+ },
+
ensureRange: function ChunkedStream_ensureRange(begin, end) {
if (begin >= end) {
return;
@@ -142,7 +155,7 @@ var ChunkedStream = (function ChunkedStreamClosure() {
if (pos >= this.end) {
return -1;
}
- this.ensureRange(pos, pos + 1);
+ this.ensureByte(pos);
return this.bytes[this.pos++];
},
--
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