Merge pull request #10986 from Snuffleupagus/inline-ensureByte-ensureRange
Attempt to significantly reduce the number of `ChunkedStream.{ensureByte, ensureRange}` calls by inlining the `this.progressiveDataLength` checks at the call-sites
This commit is contained in:
commit
0cc0789af3
@ -159,7 +159,9 @@ class ChunkedStream {
|
||||
if (pos >= this.end) {
|
||||
return -1;
|
||||
}
|
||||
this.ensureByte(pos);
|
||||
if (pos >= this.progressiveDataLength) {
|
||||
this.ensureByte(pos);
|
||||
}
|
||||
return this.bytes[this.pos++];
|
||||
}
|
||||
|
||||
@ -187,7 +189,9 @@ class ChunkedStream {
|
||||
const strEnd = this.end;
|
||||
|
||||
if (!length) {
|
||||
this.ensureRange(pos, strEnd);
|
||||
if (strEnd > this.progressiveDataLength) {
|
||||
this.ensureRange(pos, strEnd);
|
||||
}
|
||||
const subarray = bytes.subarray(pos, strEnd);
|
||||
// `this.bytes` is always a `Uint8Array` here.
|
||||
return (forceClamped ? new Uint8ClampedArray(subarray) : subarray);
|
||||
@ -197,7 +201,9 @@ class ChunkedStream {
|
||||
if (end > strEnd) {
|
||||
end = strEnd;
|
||||
}
|
||||
this.ensureRange(pos, end);
|
||||
if (end > this.progressiveDataLength) {
|
||||
this.ensureRange(pos, end);
|
||||
}
|
||||
|
||||
this.pos = end;
|
||||
const subarray = bytes.subarray(pos, end);
|
||||
@ -224,7 +230,9 @@ class ChunkedStream {
|
||||
if (end > this.end) {
|
||||
end = this.end;
|
||||
}
|
||||
this.ensureRange(begin, end);
|
||||
if (end > this.progressiveDataLength) {
|
||||
this.ensureRange(begin, end);
|
||||
}
|
||||
return this.bytes.subarray(begin, end);
|
||||
}
|
||||
|
||||
@ -245,7 +253,9 @@ class ChunkedStream {
|
||||
|
||||
makeSubStream(start, length, dict) {
|
||||
if (length) {
|
||||
this.ensureRange(start, start + length);
|
||||
if (start + length > this.progressiveDataLength) {
|
||||
this.ensureRange(start, start + length);
|
||||
}
|
||||
} else {
|
||||
// When the `length` is undefined you do *not*, under any circumstances,
|
||||
// want to fallback on calling `this.ensureRange(start, this.end)` since
|
||||
@ -256,7 +266,9 @@ class ChunkedStream {
|
||||
// time/resources during e.g. parsing, since `MissingDataException`s will
|
||||
// require data to be re-parsed, which we attempt to minimize by at least
|
||||
// checking that the *beginning* of the data is available here.
|
||||
this.ensureByte(start);
|
||||
if (start >= this.progressiveDataLength) {
|
||||
this.ensureByte(start);
|
||||
}
|
||||
}
|
||||
|
||||
function ChunkedStreamSubstream() {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user