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).
This commit is contained in:
Nicholas Nethercote 2014-03-06 16:14:21 -08:00
parent 57e896d29e
commit f12d588258

View File

@ -187,6 +187,8 @@ var ChunkedStream = (function ChunkedStreamClosure() {
}, },
makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) { makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
this.ensureRange(start, start + length);
function ChunkedStreamSubstream() {} function ChunkedStreamSubstream() {}
ChunkedStreamSubstream.prototype = Object.create(this); ChunkedStreamSubstream.prototype = Object.create(this);
ChunkedStreamSubstream.prototype.getMissingChunks = function() { ChunkedStreamSubstream.prototype.getMissingChunks = function() {