mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Deprecate ComputeHash(Val*) methods, replace with ComputeHash(Val&)
This commit is contained in:
parent
e5f66cd2e6
commit
e01d2c1b37
9 changed files with 29 additions and 22 deletions
|
@ -333,10 +333,9 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const
|
HashKey* CompositeHash::ComputeHash(const Val& argv, bool type_check) const
|
||||||
{
|
{
|
||||||
if ( ! v )
|
auto v = &argv;
|
||||||
reporter->InternalError("null value given to CompositeHash::ComputeHash");
|
|
||||||
|
|
||||||
if ( is_singleton )
|
if ( is_singleton )
|
||||||
return ComputeSingletonHash(v, type_check);
|
return ComputeSingletonHash(v, type_check);
|
||||||
|
@ -350,7 +349,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const
|
||||||
// be okay; the only thing is that the ListVal unref's it.
|
// be okay; the only thing is that the ListVal unref's it.
|
||||||
Val* ncv = (Val*) v;
|
Val* ncv = (Val*) v;
|
||||||
lv.Append({NewRef{}, ncv});
|
lv.Append({NewRef{}, ncv});
|
||||||
HashKey* hk = ComputeHash(&lv, type_check);
|
HashKey* hk = ComputeHash(lv, type_check);
|
||||||
return hk;
|
return hk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,12 @@ public:
|
||||||
~CompositeHash();
|
~CompositeHash();
|
||||||
|
|
||||||
// Compute the hash corresponding to the given index val,
|
// Compute the hash corresponding to the given index val,
|
||||||
// or 0 if it fails to typecheck.
|
// or nullptr if it fails to typecheck.
|
||||||
HashKey* ComputeHash(const Val* v, bool type_check) const;
|
HashKey* ComputeHash(const Val& v, bool type_check) const;
|
||||||
|
|
||||||
|
[[deprecated("Remove in v4.1. Pass a Val& instead.")]]
|
||||||
|
HashKey* ComputeHash(const Val* v, bool type_check) const
|
||||||
|
{ return ComputeHash(*v, type_check); }
|
||||||
|
|
||||||
// Given a hash key, recover the values used to create it.
|
// Given a hash key, recover the values used to create it.
|
||||||
IntrusivePtr<ListVal> RecoverVals(const HashKey* k) const;
|
IntrusivePtr<ListVal> RecoverVals(const HashKey* k) const;
|
||||||
|
|
|
@ -739,14 +739,14 @@ bool BloomFilterVal::Typify(IntrusivePtr<BroType> arg_type)
|
||||||
|
|
||||||
void BloomFilterVal::Add(const Val* val)
|
void BloomFilterVal::Add(const Val* val)
|
||||||
{
|
{
|
||||||
HashKey* key = hash->ComputeHash(val, true);
|
HashKey* key = hash->ComputeHash(*val, true);
|
||||||
bloom_filter->Add(key);
|
bloom_filter->Add(key);
|
||||||
delete key;
|
delete key;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BloomFilterVal::Count(const Val* val) const
|
size_t BloomFilterVal::Count(const Val* val) const
|
||||||
{
|
{
|
||||||
HashKey* key = hash->ComputeHash(val, true);
|
HashKey* key = hash->ComputeHash(*val, true);
|
||||||
size_t cnt = bloom_filter->Count(key);
|
size_t cnt = bloom_filter->Count(key);
|
||||||
delete key;
|
delete key;
|
||||||
return cnt;
|
return cnt;
|
||||||
|
@ -900,7 +900,7 @@ bool CardinalityVal::Typify(IntrusivePtr<BroType> arg_type)
|
||||||
|
|
||||||
void CardinalityVal::Add(const Val* val)
|
void CardinalityVal::Add(const Val* val)
|
||||||
{
|
{
|
||||||
HashKey* key = hash->ComputeHash(val, true);
|
HashKey* key = hash->ComputeHash(*val, true);
|
||||||
c->AddElement(key->Hash());
|
c->AddElement(key->Hash());
|
||||||
delete key;
|
delete key;
|
||||||
}
|
}
|
||||||
|
|
|
@ -719,7 +719,7 @@ SwitchStmt::~SwitchStmt()
|
||||||
|
|
||||||
bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx)
|
bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx)
|
||||||
{
|
{
|
||||||
HashKey* hk = comp_hash->ComputeHash(v, true);
|
HashKey* hk = comp_hash->ComputeHash(*v, true);
|
||||||
|
|
||||||
if ( ! hk )
|
if ( ! hk )
|
||||||
{
|
{
|
||||||
|
@ -763,7 +763,7 @@ std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const
|
||||||
// Find matching expression cases.
|
// Find matching expression cases.
|
||||||
if ( case_label_value_map.Length() )
|
if ( case_label_value_map.Length() )
|
||||||
{
|
{
|
||||||
HashKey* hk = comp_hash->ComputeHash(v, true);
|
HashKey* hk = comp_hash->ComputeHash(*v, true);
|
||||||
|
|
||||||
if ( ! hk )
|
if ( ! hk )
|
||||||
{
|
{
|
||||||
|
|
10
src/Val.cc
10
src/Val.cc
|
@ -1508,7 +1508,7 @@ void TableVal::CheckExpireAttr(attr_tag at)
|
||||||
|
|
||||||
bool TableVal::Assign(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val)
|
bool TableVal::Assign(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val)
|
||||||
{
|
{
|
||||||
HashKey* k = ComputeHash(index.get());
|
HashKey* k = ComputeHash(*index);
|
||||||
if ( ! k )
|
if ( ! k )
|
||||||
{
|
{
|
||||||
index->Error("index type doesn't match table", table_type->Indices());
|
index->Error("index type doesn't match table", table_type->Indices());
|
||||||
|
@ -1910,7 +1910,7 @@ IntrusivePtr<Val> TableVal::Lookup(Val* index, bool use_default_val)
|
||||||
|
|
||||||
if ( tbl->Length() > 0 )
|
if ( tbl->Length() > 0 )
|
||||||
{
|
{
|
||||||
HashKey* k = ComputeHash(index);
|
HashKey* k = ComputeHash(*index);
|
||||||
if ( k )
|
if ( k )
|
||||||
{
|
{
|
||||||
TableEntryVal* v = AsTable()->Lookup(k);
|
TableEntryVal* v = AsTable()->Lookup(k);
|
||||||
|
@ -1985,7 +1985,7 @@ bool TableVal::UpdateTimestamp(Val* index)
|
||||||
v = (TableEntryVal*) subnets->Lookup(index);
|
v = (TableEntryVal*) subnets->Lookup(index);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
HashKey* k = ComputeHash(index);
|
HashKey* k = ComputeHash(*index);
|
||||||
if ( ! k )
|
if ( ! k )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -2070,7 +2070,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe
|
||||||
|
|
||||||
IntrusivePtr<Val> TableVal::Delete(const Val* index)
|
IntrusivePtr<Val> TableVal::Delete(const Val* index)
|
||||||
{
|
{
|
||||||
HashKey* k = ComputeHash(index);
|
HashKey* k = ComputeHash(*index);
|
||||||
TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : nullptr;
|
TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : nullptr;
|
||||||
IntrusivePtr<Val> va;
|
IntrusivePtr<Val> va;
|
||||||
|
|
||||||
|
@ -2594,7 +2594,7 @@ unsigned int TableVal::MemoryAllocation() const
|
||||||
+ table_hash->MemoryAllocation();
|
+ table_hash->MemoryAllocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
HashKey* TableVal::ComputeHash(const Val* index) const
|
HashKey* TableVal::ComputeHash(const Val& index) const
|
||||||
{
|
{
|
||||||
return table_hash->ComputeHash(index, true);
|
return table_hash->ComputeHash(index, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -892,7 +892,11 @@ public:
|
||||||
timer = nullptr;
|
timer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashKey* ComputeHash(const Val* index) const;
|
HashKey* ComputeHash(const Val& index) const;
|
||||||
|
|
||||||
|
[[deprecated("Remove in v4.1. Pass a Val& instead.")]]
|
||||||
|
HashKey* ComputeHash(const Val* index) const
|
||||||
|
{ return ComputeHash(*index); }
|
||||||
|
|
||||||
notifier::Modifiable* Modifiable() override { return this; }
|
notifier::Modifiable* Modifiable() override { return this; }
|
||||||
|
|
||||||
|
|
|
@ -163,11 +163,11 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set)
|
||||||
|
|
||||||
HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const
|
HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const
|
||||||
{
|
{
|
||||||
ListVal* lv = new ListVal(TYPE_ANY);
|
auto lv = make_intrusive<ListVal>(TYPE_ANY);
|
||||||
lv->Append(t.AsVal());
|
lv->Append(t.AsVal());
|
||||||
lv->Append({NewRef{}, args});
|
lv->Append({NewRef{}, args});
|
||||||
HashKey* key = analyzer_hash->ComputeHash(lv, true);
|
HashKey* key = analyzer_hash->ComputeHash(*lv, true);
|
||||||
Unref(lv);
|
|
||||||
if ( ! key )
|
if ( ! key )
|
||||||
reporter->InternalError("AnalyzerArgs type mismatch");
|
reporter->InternalError("AnalyzerArgs type mismatch");
|
||||||
|
|
||||||
|
|
|
@ -1248,7 +1248,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals)
|
||||||
oldval = stream->tab->Lookup(idxval, false);
|
oldval = stream->tab->Lookup(idxval, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
HashKey* k = stream->tab->ComputeHash(idxval);
|
HashKey* k = stream->tab->ComputeHash(*idxval);
|
||||||
if ( ! k )
|
if ( ! k )
|
||||||
reporter->InternalError("could not hash");
|
reporter->InternalError("could not hash");
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ void TopkVal::Typify(IntrusivePtr<BroType> t)
|
||||||
|
|
||||||
HashKey* TopkVal::GetHash(Val* v) const
|
HashKey* TopkVal::GetHash(Val* v) const
|
||||||
{
|
{
|
||||||
HashKey* key = hash->ComputeHash(v, true);
|
HashKey* key = hash->ComputeHash(*v, true);
|
||||||
assert(key);
|
assert(key);
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue