Deprecate ComputeHash(Val*) methods, replace with ComputeHash(Val&)

This commit is contained in:
Jon Siwek 2020-05-20 15:47:19 -07:00
parent e5f66cd2e6
commit e01d2c1b37
9 changed files with 29 additions and 22 deletions

View file

@ -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 )
reporter->InternalError("null value given to CompositeHash::ComputeHash");
auto v = &argv;
if ( is_singleton )
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.
Val* ncv = (Val*) v;
lv.Append({NewRef{}, ncv});
HashKey* hk = ComputeHash(&lv, type_check);
HashKey* hk = ComputeHash(lv, type_check);
return hk;
}

View file

@ -14,8 +14,12 @@ public:
~CompositeHash();
// Compute the hash corresponding to the given index val,
// or 0 if it fails to typecheck.
HashKey* ComputeHash(const Val* v, bool type_check) const;
// or nullptr if it fails to typecheck.
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.
IntrusivePtr<ListVal> RecoverVals(const HashKey* k) const;

View file

@ -739,14 +739,14 @@ bool BloomFilterVal::Typify(IntrusivePtr<BroType> arg_type)
void BloomFilterVal::Add(const Val* val)
{
HashKey* key = hash->ComputeHash(val, true);
HashKey* key = hash->ComputeHash(*val, true);
bloom_filter->Add(key);
delete key;
}
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);
delete key;
return cnt;
@ -900,7 +900,7 @@ bool CardinalityVal::Typify(IntrusivePtr<BroType> arg_type)
void CardinalityVal::Add(const Val* val)
{
HashKey* key = hash->ComputeHash(val, true);
HashKey* key = hash->ComputeHash(*val, true);
c->AddElement(key->Hash());
delete key;
}

View file

@ -719,7 +719,7 @@ SwitchStmt::~SwitchStmt()
bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx)
{
HashKey* hk = comp_hash->ComputeHash(v, true);
HashKey* hk = comp_hash->ComputeHash(*v, true);
if ( ! hk )
{
@ -763,7 +763,7 @@ std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const
// Find matching expression cases.
if ( case_label_value_map.Length() )
{
HashKey* hk = comp_hash->ComputeHash(v, true);
HashKey* hk = comp_hash->ComputeHash(*v, true);
if ( ! hk )
{

View file

@ -1508,7 +1508,7 @@ void TableVal::CheckExpireAttr(attr_tag at)
bool TableVal::Assign(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val)
{
HashKey* k = ComputeHash(index.get());
HashKey* k = ComputeHash(*index);
if ( ! k )
{
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 )
{
HashKey* k = ComputeHash(index);
HashKey* k = ComputeHash(*index);
if ( k )
{
TableEntryVal* v = AsTable()->Lookup(k);
@ -1985,7 +1985,7 @@ bool TableVal::UpdateTimestamp(Val* index)
v = (TableEntryVal*) subnets->Lookup(index);
else
{
HashKey* k = ComputeHash(index);
HashKey* k = ComputeHash(*index);
if ( ! k )
return false;
@ -2070,7 +2070,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe
IntrusivePtr<Val> TableVal::Delete(const Val* index)
{
HashKey* k = ComputeHash(index);
HashKey* k = ComputeHash(*index);
TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : nullptr;
IntrusivePtr<Val> va;
@ -2594,7 +2594,7 @@ unsigned int TableVal::MemoryAllocation() const
+ table_hash->MemoryAllocation();
}
HashKey* TableVal::ComputeHash(const Val* index) const
HashKey* TableVal::ComputeHash(const Val& index) const
{
return table_hash->ComputeHash(index, true);
}

View file

@ -892,7 +892,11 @@ public:
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; }

View file

@ -163,11 +163,11 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set)
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({NewRef{}, args});
HashKey* key = analyzer_hash->ComputeHash(lv, true);
Unref(lv);
HashKey* key = analyzer_hash->ComputeHash(*lv, true);
if ( ! key )
reporter->InternalError("AnalyzerArgs type mismatch");

View file

@ -1248,7 +1248,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals)
oldval = stream->tab->Lookup(idxval, false);
}
HashKey* k = stream->tab->ComputeHash(idxval);
HashKey* k = stream->tab->ComputeHash(*idxval);
if ( ! k )
reporter->InternalError("could not hash");

View file

@ -29,7 +29,7 @@ void TopkVal::Typify(IntrusivePtr<BroType> t)
HashKey* TopkVal::GetHash(Val* v) const
{
HashKey* key = hash->ComputeHash(v, true);
HashKey* key = hash->ComputeHash(*v, true);
assert(key);
return key;
}