1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-01 01:44:22 +03:00

Introduce an Iterator class in PriorityQueue

Summary: The abstraction layer here was not great

Reviewed By: afrind

Differential Revision: D43427138

fbshipit-source-id: 7fb7cfe278995e58f05bda3354ef53bc407af2a2
This commit is contained in:
Paul Farcasanu
2023-03-23 10:43:24 -07:00
committed by Facebook GitHub Bot
parent d62f9b5b79
commit 36c85fa724
4 changed files with 111 additions and 48 deletions

View File

@ -450,42 +450,25 @@ void StreamFrameScheduler::writeStreamsHelper(
builder.remainingSpaceInPkt() > 0;
index++) {
PriorityQueue::Level& level = writableStreams.levels[index];
if (level.streams.empty()) {
if (level.empty()) {
// No data here, keep going
continue;
}
if (level.incremental) {
// Round robin the streams at this level
MiddleStartingIterationWrapper wrapper(level.streams, level.next);
auto writableStreamItr = wrapper.cbegin();
while (writableStreamItr != wrapper.cend()) {
auto stream = conn_.streamManager->findStream(*writableStreamItr);
CHECK(stream);
if (!writeSingleStream(builder, *stream, connWritableBytes)) {
break;
}
writableStreamItr++;
if (streamPerPacket) {
level.next = writableStreamItr.rawIterator();
return;
}
level.iterator->begin();
do {
auto streamId = level.iterator->current();
auto stream = conn_.streamManager->findStream(streamId);
CHECK(stream) << "streamId=" << streamId
<< "inc=" << uint64_t(level.incremental);
if (!writeSingleStream(builder, *stream, connWritableBytes)) {
break;
}
level.next = writableStreamItr.rawIterator();
} else {
// walk the sequential streams in order until we run out of space
for (auto streamIt = level.streams.begin();
streamIt != level.streams.end();
++streamIt) {
auto stream = conn_.streamManager->findStream(*streamIt);
CHECK(stream);
if (!writeSingleStream(builder, *stream, connWritableBytes)) {
break;
}
if (streamPerPacket) {
return;
}
level.iterator->next();
if (streamPerPacket) {
return;
}
}
} while (!level.iterator->end());
}
}