mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
refactor: slot_set don't use stack memory anymore (#4386)
This commit is contained in:
parent
810af83074
commit
c5b3584dfd
1 changed files with 16 additions and 7 deletions
|
@ -18,21 +18,21 @@ class SlotSet {
|
||||||
using TBitSet = std::bitset<kSlotsNumber>;
|
using TBitSet = std::bitset<kSlotsNumber>;
|
||||||
|
|
||||||
SlotSet(bool full_house = false) {
|
SlotSet(bool full_house = false) {
|
||||||
|
slots_ = std::make_unique<TBitSet>();
|
||||||
if (full_house)
|
if (full_house)
|
||||||
slots_->flip();
|
slots_->flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
SlotSet(const SlotRanges& slot_ranges) {
|
SlotSet(const SlotRanges& slot_ranges) {
|
||||||
|
slots_ = std::make_unique<TBitSet>();
|
||||||
Set(slot_ranges, true);
|
Set(slot_ranges, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SlotSet(const TBitSet& s) {
|
SlotSet(const SlotSet& s) {
|
||||||
*slots_ = s;
|
slots_ = std::make_unique<TBitSet>(*s.slots_);
|
||||||
}
|
}
|
||||||
|
|
||||||
SlotSet(const SlotSet& s) {
|
SlotSet(SlotSet&& s) = default;
|
||||||
*slots_ = *s.slots_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Contains(SlotId slot) const {
|
bool Contains(SlotId slot) const {
|
||||||
return slots_->test(slot);
|
return slots_->test(slot);
|
||||||
|
@ -64,7 +64,11 @@ class SlotSet {
|
||||||
|
|
||||||
// Get SlotSet that are absent in the slots
|
// Get SlotSet that are absent in the slots
|
||||||
SlotSet GetRemovedSlots(const SlotSet& slots) const {
|
SlotSet GetRemovedSlots(const SlotSet& slots) const {
|
||||||
return *slots_ & ~*slots.slots_;
|
// we need to avoid stack usage to prevent stack overflow
|
||||||
|
SlotSet res(slots);
|
||||||
|
res.slots_->flip();
|
||||||
|
*res.slots_ &= *slots_;
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
SlotRanges ToSlotRanges() const {
|
SlotRanges ToSlotRanges() const {
|
||||||
|
@ -85,7 +89,12 @@ class SlotSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<TBitSet> slots_{std::make_unique<TBitSet>()};
|
SlotSet(std::unique_ptr<TBitSet> s) {
|
||||||
|
slots_ = std::move(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<TBitSet> slots_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dfly::cluster
|
} // namespace dfly::cluster
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue