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