mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +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()) {
|
if (!stack_.empty()) {
|
||||||
stack_.top().first->arr.push_back(std::move(val));
|
auto& last = stack_.top();
|
||||||
stack_.top().second--;
|
last.first->arr.push_back(std::move(val));
|
||||||
|
if (collapse_if_needed && last.second-- == 1) {
|
||||||
|
CollapseFilledCollections();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
DCHECK_EQ(current_.index(), 0u);
|
DCHECK_EQ(current_.index(), 0u);
|
||||||
current_ = std::move(val);
|
current_ = std::move(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we filled up a collection.
|
|
||||||
CollapseFilledCollections();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CapturingReplyBuilder::CollapseFilledCollections() {
|
void CapturingReplyBuilder::CollapseFilledCollections() {
|
||||||
while (!stack_.empty() && stack_.top().second == 0) {
|
while (!stack_.empty() && stack_.top().second == 0) {
|
||||||
auto pl = std::move(stack_.top());
|
auto pl = std::move(stack_.top());
|
||||||
stack_.pop();
|
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);
|
void SendDirect(Payload&& val);
|
||||||
|
|
||||||
// Capture value and store eiter in current topmost collection or as a standalone value.
|
// 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.
|
// While topmost collection in stack is full, finalize it and add it as a regular value.
|
||||||
void CollapseFilledCollections();
|
void CollapseFilledCollections();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue