From f12d5882580c780db052cc327c09f1165f67b4ff Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 6 Mar 2014 16:14:21 -0800 Subject: [PATCH] Add an ensureRange() call to ChunkedStream_makeSubStream(). By checking if the data is all present before making a substream, we avoid cases where we parse part of a stream and then throw a MissingDataException part-way through, which forces us to later re-read the stream -- possibly multiple times. This is a sizeable performance win for some cases when file loading is slow (e.g. over the web). --- src/core/chunked_stream.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index 040151815..98e8d7216 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -187,6 +187,8 @@ var ChunkedStream = (function ChunkedStreamClosure() { }, makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) { + this.ensureRange(start, start + length); + function ChunkedStreamSubstream() {} ChunkedStreamSubstream.prototype = Object.create(this); ChunkedStreamSubstream.prototype.getMissingChunks = function() {