mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Improve TableVal HashKey management
* Deprecated ComputeHash() methods and replaced with MakeHashKey() which returns std::unique_ptr<HashKey> * Deprecated RecoverIndex() and replaced with RecreateIndex() which takes HashKey& and returns IntrusivePtr. * Updated the new TableVal Assign()/Remove() methods to take either std::unique_ptr<HashKey> or HashKey& as appropriate for clarity of ownership expectations.
This commit is contained in:
parent
8a6a92c348
commit
3f92df51b7
18 changed files with 137 additions and 114 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Type.h"
|
||||
#include "IntrusivePtr.h"
|
||||
|
||||
|
@ -15,19 +17,23 @@ public:
|
|||
|
||||
// Compute the hash corresponding to the given index val,
|
||||
// or nullptr if it fails to typecheck.
|
||||
HashKey* ComputeHash(const Val& v, bool type_check) const;
|
||||
std::unique_ptr<HashKey> MakeHashKey(const Val& v, bool type_check) const;
|
||||
|
||||
[[deprecated("Remove in v4.1. Pass a Val& instead.")]]
|
||||
[[deprecated("Remove in v4.1. Use MakeHashKey().")]]
|
||||
HashKey* ComputeHash(const Val* v, bool type_check) const
|
||||
{ return ComputeHash(*v, type_check); }
|
||||
{ return MakeHashKey(*v, type_check).release(); }
|
||||
|
||||
// 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;
|
||||
|
||||
[[deprecated("Remove in v4.1. Pass in HashKey& instead.")]]
|
||||
IntrusivePtr<ListVal> RecoverVals(const HashKey* k) const
|
||||
{ return RecoverVals(*k); }
|
||||
|
||||
unsigned int MemoryAllocation() const { return padded_sizeof(*this) + pad_size(size); }
|
||||
|
||||
protected:
|
||||
HashKey* ComputeSingletonHash(const Val* v, bool type_check) const;
|
||||
std::unique_ptr<HashKey> ComputeSingletonHash(const Val* v, bool type_check) const;
|
||||
|
||||
// Computes the piece of the hash for Val*, returning the new kp.
|
||||
// Used as a helper for ComputeHash in the non-singleton case.
|
||||
|
@ -38,7 +44,7 @@ protected:
|
|||
// Upon return, pval will point to the recovered Val of type t.
|
||||
// Returns and updated kp for the next Val. Calls reporter->InternalError()
|
||||
// upon errors, so there is no return value for invalid input.
|
||||
const char* RecoverOneVal(const HashKey* k,
|
||||
const char* RecoverOneVal(const HashKey& k,
|
||||
const char* kp, const char* const k_end,
|
||||
BroType* t, IntrusivePtr<Val>* pval, bool optional) const;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue