mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
chore: get rid of possible recursion when unwinding structured reply (#5012)
This commit is contained in:
parent
dced0371d3
commit
befb36d477
2 changed files with 8 additions and 8 deletions
|
@ -81,24 +81,24 @@ void CapturingReplyBuilder::SendDirect(Payload&& val) {
|
|||
}
|
||||
}
|
||||
|
||||
void CapturingReplyBuilder::Capture(Payload val) {
|
||||
void CapturingReplyBuilder::Capture(Payload val, bool collapse_if_needed) {
|
||||
if (!stack_.empty()) {
|
||||
stack_.top().first->arr.push_back(std::move(val));
|
||||
stack_.top().second--;
|
||||
auto& last = stack_.top();
|
||||
last.first->arr.push_back(std::move(val));
|
||||
if (collapse_if_needed && last.second-- == 1) {
|
||||
CollapseFilledCollections();
|
||||
}
|
||||
} else {
|
||||
DCHECK_EQ(current_.index(), 0u);
|
||||
current_ = std::move(val);
|
||||
}
|
||||
|
||||
// Check if we filled up a collection.
|
||||
CollapseFilledCollections();
|
||||
}
|
||||
|
||||
void CapturingReplyBuilder::CollapseFilledCollections() {
|
||||
while (!stack_.empty() && stack_.top().second == 0) {
|
||||
auto pl = std::move(stack_.top());
|
||||
stack_.pop();
|
||||
Capture(std::move(pl.first));
|
||||
Capture(std::move(pl.first), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ class CapturingReplyBuilder : public RedisReplyBuilder {
|
|||
void SendDirect(Payload&& val);
|
||||
|
||||
// Capture value and store eiter in current topmost collection or as a standalone value.
|
||||
void Capture(Payload val);
|
||||
void Capture(Payload val, bool collapse_if_needed = true);
|
||||
|
||||
// While topmost collection in stack is full, finalize it and add it as a regular value.
|
||||
void CollapseFilledCollections();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue