Skip to content

Commit f73f587

Browse files
authored
Editorial: small cleanup after #1326
This reduces some repetitions, and uses the list size of filledPullIntos instead of a separate counter.
1 parent fa4891a commit f73f587

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

index.bs

+10-12
Original file line numberDiff line numberDiff line change
@@ -3352,8 +3352,7 @@ The following abstract operations support the implementation of the
33523352
! [$ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue$](|controller|).
33533353
1. [=list/For each=] |filledPullInto| of |filledPullIntos|,
33543354
1. Perform !
3355-
[$ReadableByteStreamControllerCommitPullIntoDescriptor$](|controller|.[=ReadableByteStreamController/[[stream]]=],
3356-
|filledPullInto|).
3355+
[$ReadableByteStreamControllerCommitPullIntoDescriptor$](|stream|, |filledPullInto|).
33573356
1. Otherwise,
33583357
1. Assert: ! [$IsReadableStreamLocked$](|stream|) is false.
33593358
1. Perform ! [$ReadableByteStreamControllerEnqueueChunkToQueue$](|controller|,
@@ -3458,18 +3457,18 @@ The following abstract operations support the implementation of the
34583457
queue entry/byte length=]).
34593458
1. Let |destStart| be |pullIntoDescriptor|'s [=pull-into descriptor/byte offset=] +
34603459
|pullIntoDescriptor|'s [=pull-into descriptor/bytes filled=].
3461-
1. Assert: ! [$CanCopyDataBlockBytes$](|pullIntoDescriptor|'s [=pull-into descriptor/buffer=],
3462-
|destStart|, |headOfQueue|'s [=readable byte stream queue entry/buffer=],
3463-
|headOfQueue|'s [=readable byte stream queue entry/byte offset=], |bytesToCopy|) is true.
3460+
1. Let |descriptorBuffer| be |pullIntoDescriptor|'s [=pull-into descriptor/buffer=].
3461+
1. Let |queueBuffer| be |headOfQueue|'s [=readable byte stream queue entry/buffer=].
3462+
1. Let |queueByteOffset| be |headOfQueue|'s [=readable byte stream queue entry/byte offset=].
3463+
1. Assert: ! [$CanCopyDataBlockBytes$](|descriptorBuffer|, |destStart|, |queueBuffer|,
3464+
|queueByteOffset|, |bytesToCopy|) is true.
34643465
<p class="warning">If this assertion were to fail (due to a bug in this specification or
34653466
its implementation), then the next step may read from or write to potentially invalid memory.
34663467
The user agent should always check this assertion, and stop in an [=implementation-defined=]
34673468
manner if it fails (e.g. by crashing the process, or by
34683469
<a abstract-op lt="ReadableByteStreamControllerError">erroring the stream</a>).
3469-
1. Perform ! [$CopyDataBlockBytes$](|pullIntoDescriptor|'s [=pull-into
3470-
descriptor/buffer=].\[[ArrayBufferData]], |destStart|,
3471-
|headOfQueue|'s [=readable byte stream queue entry/buffer=].\[[ArrayBufferData]],
3472-
|headOfQueue|'s [=readable byte stream queue entry/byte offset=], |bytesToCopy|).
3470+
1. Perform ! [$CopyDataBlockBytes$](|descriptorBuffer|.\[[ArrayBufferData]], |destStart|,
3471+
|queueBuffer|.\[[ArrayBufferData]], |queueByteOffset|, |bytesToCopy|).
34733472
1. If |headOfQueue|'s [=readable byte stream queue entry/byte length=] is |bytesToCopy|,
34743473
1. [=list/Remove=] |queue|[0].
34753474
1. Otherwise,
@@ -3716,12 +3715,11 @@ The following abstract operations support the implementation of the
37163715
1. Let |stream| be |controller|.[=ReadableByteStreamController/[[stream]]=].
37173716
1. If ! [$ReadableStreamHasBYOBReader$](|stream|) is true,
37183717
1. Let |filledPullIntos| be a new empty [=list=].
3719-
1. Let |i| be 0.
3720-
1. [=While=] |i| < ! [$ReadableStreamGetNumReadIntoRequests$](|stream|),
3718+
1. [=While=] |filledPullIntos|'s [=list/size=] < !
3719+
[$ReadableStreamGetNumReadIntoRequests$](|stream|),
37213720
1. Let |pullIntoDescriptor| be !
37223721
[$ReadableByteStreamControllerShiftPendingPullInto$](|controller|).
37233722
1. [=list/Append=] |pullIntoDescriptor| to |filledPullIntos|.
3724-
1. Set |i| to |i| + 1.
37253723
1. [=list/For each=] |filledPullInto| of |filledPullIntos|,
37263724
1. Perform ! [$ReadableByteStreamControllerCommitPullIntoDescriptor$](|stream|,
37273725
|filledPullInto|).

reference-implementation/lib/abstract-ops/readable-streams.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ function ReadableByteStreamControllerEnqueue(controller, chunk) {
13621362
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
13631363
const filledPullIntos = ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);
13641364
for (const filledPullInto of filledPullIntos) {
1365-
ReadableByteStreamControllerCommitPullIntoDescriptor(controller._stream, filledPullInto);
1365+
ReadableByteStreamControllerCommitPullIntoDescriptor(stream, filledPullInto);
13661366
}
13671367
} else {
13681368
assert(IsReadableStreamLocked(stream) === false);
@@ -1448,9 +1448,12 @@ function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller,
14481448

14491449
const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;
14501450

1451-
assert(CanCopyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset,
1451+
const descriptorBuffer = pullIntoDescriptor.buffer;
1452+
const queueBuffer = headOfQueue.buffer;
1453+
const queueByteOffset = headOfQueue.byteOffset;
1454+
assert(CanCopyDataBlockBytes(descriptorBuffer, destStart, queueBuffer, queueByteOffset,
14521455
bytesToCopy));
1453-
CopyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);
1456+
CopyDataBlockBytes(descriptorBuffer, destStart, queueBuffer, queueByteOffset, bytesToCopy);
14541457

14551458
if (headOfQueue.byteLength === bytesToCopy) {
14561459
queue.shift();
@@ -1680,11 +1683,9 @@ function ReadableByteStreamControllerRespondInClosedState(controller, firstDescr
16801683
const stream = controller._stream;
16811684
if (ReadableStreamHasBYOBReader(stream) === true) {
16821685
const filledPullIntos = [];
1683-
let i = 0;
1684-
while (i < ReadableStreamGetNumReadIntoRequests(stream)) {
1686+
while (filledPullIntos.length < ReadableStreamGetNumReadIntoRequests(stream)) {
16851687
const pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller);
16861688
filledPullIntos.push(pullIntoDescriptor);
1687-
++i;
16881689
}
16891690
for (const filledPullInto of filledPullIntos) {
16901691
ReadableByteStreamControllerCommitPullIntoDescriptor(stream, filledPullInto);

0 commit comments

Comments
 (0)