Skip to content

Commit 4babab7

Browse files
committed
Eliminate recursion for TCO
1 parent ae612f0 commit 4babab7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/workerd/api/streams/compression.c++

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,20 @@ public:
163163
}
164164

165165
kj::Promise<void> write(kj::ArrayPtr<const kj::ArrayPtr<const kj::byte>> pieces) override {
166+
// We check for Ended, Exception here so that we catch
167+
// these even if pieces is empty.
166168
KJ_SWITCH_ONEOF(state) {
167169
KJ_CASE_ONEOF(ended, Ended) {
168170
JSG_FAIL_REQUIRE(Error, "Write after close");
169171
}
170-
KJ_CASE_ONEOF(exception, kj::Exception) { kj::throwFatalException(kj::cp(exception)); }
172+
KJ_CASE_ONEOF(exception, kj::Exception) {
173+
kj::throwFatalException(kj::cp(exception));
174+
}
171175
KJ_CASE_ONEOF(open, Open) {
172-
if (pieces.size() != 0) {
173-
co_await write(pieces[0].begin(), pieces[0].size());
174-
co_await write(pieces.slice(1, pieces.size()));
176+
for (auto &piece : pieces) {
177+
if (piece.size() != 0) {
178+
co_await write(piece.begin(), piece.size());
179+
}
175180
}
176181
co_return;
177182
}

0 commit comments

Comments
 (0)