mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
CompHash: use class IntrusivePtr for the type
field
This commit is contained in:
parent
31b3a56740
commit
53f49e0057
7 changed files with 17 additions and 22 deletions
|
@ -13,10 +13,9 @@
|
|||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
CompositeHash::CompositeHash(TypeList* composite_type)
|
||||
CompositeHash::CompositeHash(IntrusivePtr<TypeList> composite_type)
|
||||
:type(std::move(composite_type))
|
||||
{
|
||||
type = composite_type;
|
||||
Ref(type);
|
||||
singleton_tag = TYPE_INTERNAL_ERROR;
|
||||
|
||||
// If the only element is a record, don't treat it as a
|
||||
|
@ -66,7 +65,6 @@ CompositeHash::CompositeHash(TypeList* composite_type)
|
|||
|
||||
CompositeHash::~CompositeHash()
|
||||
{
|
||||
Unref(type);
|
||||
delete [] key;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "Type.h"
|
||||
#include "IntrusivePtr.h"
|
||||
|
||||
class ListVal;
|
||||
class HashKey;
|
||||
|
||||
class CompositeHash {
|
||||
public:
|
||||
explicit CompositeHash(TypeList* composite_type);
|
||||
explicit CompositeHash(IntrusivePtr<TypeList> composite_type);
|
||||
~CompositeHash();
|
||||
|
||||
// Compute the hash corresponding to the given index val,
|
||||
|
@ -78,7 +79,7 @@ protected:
|
|||
int type_check, int sz, bool optional,
|
||||
bool calc_static_size) const;
|
||||
|
||||
TypeList* type;
|
||||
IntrusivePtr<TypeList> type;
|
||||
char* key; // space for composite key
|
||||
int size;
|
||||
int is_singleton; // if just one type in index
|
||||
|
|
|
@ -791,10 +791,9 @@ bool BloomFilterVal::Typify(BroType* arg_type)
|
|||
type = arg_type;
|
||||
type->Ref();
|
||||
|
||||
TypeList* tl = new TypeList(type);
|
||||
auto tl = make_intrusive<TypeList>(type);
|
||||
tl->Append(type->Ref());
|
||||
hash = new CompositeHash(tl);
|
||||
Unref(tl);
|
||||
hash = new CompositeHash(std::move(tl));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -963,10 +962,9 @@ bool CardinalityVal::Typify(BroType* arg_type)
|
|||
type = arg_type;
|
||||
type->Ref();
|
||||
|
||||
TypeList* tl = new TypeList(type);
|
||||
auto tl = make_intrusive<TypeList>(type);
|
||||
tl->Append(type->Ref());
|
||||
hash = new CompositeHash(tl);
|
||||
Unref(tl);
|
||||
hash = new CompositeHash(std::move(tl));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -602,10 +602,9 @@ static void int_del_func(void* v)
|
|||
|
||||
void SwitchStmt::Init()
|
||||
{
|
||||
TypeList* t = new TypeList();
|
||||
auto t = make_intrusive<TypeList>();
|
||||
t->Append(e->Type()->Ref());
|
||||
comp_hash = new CompositeHash(t);
|
||||
Unref(t);
|
||||
comp_hash = new CompositeHash(std::move(t));
|
||||
|
||||
case_label_value_map.SetDeleteFunc(int_del_func);
|
||||
}
|
||||
|
|
|
@ -1352,7 +1352,8 @@ void TableVal::Init(TableType* t)
|
|||
else
|
||||
subnets = 0;
|
||||
|
||||
table_hash = new CompositeHash(table_type->Indices());
|
||||
table_hash = new CompositeHash(IntrusivePtr<TypeList>(NewRef{},
|
||||
table_type->Indices()));
|
||||
val.table_val = new PDict<TableEntryVal>;
|
||||
val.table_val->SetDeleteFunc(table_entry_val_delete_func);
|
||||
}
|
||||
|
|
|
@ -20,11 +20,10 @@ static void analyzer_del_func(void* v)
|
|||
|
||||
AnalyzerSet::AnalyzerSet(File* arg_file) : file(arg_file)
|
||||
{
|
||||
TypeList* t = new TypeList();
|
||||
auto t = make_intrusive<TypeList>();
|
||||
t->Append(file_mgr->GetTagEnumType()->Ref());
|
||||
t->Append(BifType::Record::Files::AnalyzerArgs->Ref());
|
||||
analyzer_hash = new CompositeHash(t);
|
||||
Unref(t);
|
||||
analyzer_hash = new CompositeHash(std::move(t));
|
||||
analyzer_map.SetDeleteFunc(analyzer_del_func);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,10 +27,9 @@ void TopkVal::Typify(BroType* t)
|
|||
{
|
||||
assert(!hash && !type);
|
||||
type = t->Ref();
|
||||
TypeList* tl = new TypeList(t);
|
||||
auto tl = make_intrusive<TypeList>(t);
|
||||
tl->Append(t->Ref());
|
||||
hash = new CompositeHash(tl);
|
||||
Unref(tl);
|
||||
hash = new CompositeHash(std::move(tl));
|
||||
}
|
||||
|
||||
HashKey* TopkVal::GetHash(Val* v) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue