Skip to content

Commit befb36d

Browse files
authored
chore: get rid of possible recursion when unwinding structured reply (#5012)
1 parent dced037 commit befb36d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/facade/reply_capture.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,24 @@ void CapturingReplyBuilder::SendDirect(Payload&& val) {
8181
}
8282
}
8383

84-
void CapturingReplyBuilder::Capture(Payload val) {
84+
void CapturingReplyBuilder::Capture(Payload val, bool collapse_if_needed) {
8585
if (!stack_.empty()) {
86-
stack_.top().first->arr.push_back(std::move(val));
87-
stack_.top().second--;
86+
auto& last = stack_.top();
87+
last.first->arr.push_back(std::move(val));
88+
if (collapse_if_needed && last.second-- == 1) {
89+
CollapseFilledCollections();
90+
}
8891
} else {
8992
DCHECK_EQ(current_.index(), 0u);
9093
current_ = std::move(val);
9194
}
92-
93-
// Check if we filled up a collection.
94-
CollapseFilledCollections();
9595
}
9696

9797
void CapturingReplyBuilder::CollapseFilledCollections() {
9898
while (!stack_.empty() && stack_.top().second == 0) {
9999
auto pl = std::move(stack_.top());
100100
stack_.pop();
101-
Capture(std::move(pl.first));
101+
Capture(std::move(pl.first), false);
102102
}
103103
}
104104

src/facade/reply_capture.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class CapturingReplyBuilder : public RedisReplyBuilder {
7979
void SendDirect(Payload&& val);
8080

8181
// Capture value and store eiter in current topmost collection or as a standalone value.
82-
void Capture(Payload val);
82+
void Capture(Payload val, bool collapse_if_needed = true);
8383

8484
// While topmost collection in stack is full, finalize it and add it as a regular value.
8585
void CollapseFilledCollections();

0 commit comments

Comments
 (0)