TableVal: Replace raw subnets/pattern_matcher with unique_ptr

This commit is contained in:
Arne Welzel 2023-11-21 11:12:09 +01:00
parent 36c43d2aa3
commit cf9afd7b77
2 changed files with 6 additions and 9 deletions

View file

@ -1563,12 +1563,10 @@ void TableVal::Init(TableTypePtr t, bool ordered) {
def_val = nullptr; def_val = nullptr;
if ( table_type->IsSubNetIndex() ) if ( table_type->IsSubNetIndex() )
subnets = new detail::PrefixTable; subnets = std::make_unique<detail::PrefixTable>();
else
subnets = nullptr;
if ( table_type->IsPatternIndex() ) if ( table_type->IsPatternIndex() )
pattern_matcher = new detail::TablePatternMatcher(this, table_type->Yield()); pattern_matcher = std::make_unique<detail::TablePatternMatcher>(this, table_type->Yield());
table_hash = new detail::CompositeHash(table_type->GetIndices()); table_hash = new detail::CompositeHash(table_type->GetIndices());
if ( ordered ) if ( ordered )
@ -1585,8 +1583,6 @@ TableVal::~TableVal() {
delete table_hash; delete table_hash;
delete table_val; delete table_val;
delete subnets;
delete pattern_matcher;
delete expire_iterator; delete expire_iterator;
} }

View file

@ -939,7 +939,8 @@ public:
// Returns the Prefix table used inside the table (if present). // Returns the Prefix table used inside the table (if present).
// This allows us to do more direct queries to this specialized // This allows us to do more direct queries to this specialized
// type that the general Table API does not allow. // type that the general Table API does not allow.
const detail::PrefixTable* Subnets() const { return subnets; } const detail::PrefixTable* Subnets() const { return subnets.get(); }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -1048,8 +1049,8 @@ protected:
detail::ExprPtr expire_func; detail::ExprPtr expire_func;
TableValTimer* timer; TableValTimer* timer;
RobustDictIterator<TableEntryVal>* expire_iterator; RobustDictIterator<TableEntryVal>* expire_iterator;
detail::PrefixTable* subnets; std::unique_ptr<detail::PrefixTable> subnets;
detail::TablePatternMatcher* pattern_matcher = nullptr; std::unique_ptr<detail::TablePatternMatcher> pattern_matcher;
ValPtr def_val; ValPtr def_val;
detail::ExprPtr change_func; detail::ExprPtr change_func;
std::string broker_store; std::string broker_store;