mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 20:48:21 +00:00
to avoid recursion, track all aggregates, not just records
isolate the internal methods
This commit is contained in:
parent
7fd94f82a8
commit
58cdc0be09
2 changed files with 61 additions and 38 deletions
48
src/Val.h
48
src/Val.h
|
@ -131,21 +131,10 @@ public:
|
|||
*/
|
||||
unsigned int Footprint() const
|
||||
{
|
||||
std::set<const RecordVal*> analyzed_records;
|
||||
return Footprint(&analyzed_records);
|
||||
std::unordered_set<const Val*> analyzed_vals;
|
||||
return Footprint(&analyzed_vals);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function for computing a Val's "footprint".
|
||||
*
|
||||
* @param analyzed_records A pointer to a set used to track which
|
||||
* records have been analyzed to date, used to prevent infinite
|
||||
* recursion. The set should be empty (but not nil) on the first call.
|
||||
*
|
||||
* @return The total footprint.
|
||||
*/
|
||||
virtual unsigned int Footprint(std::set<const RecordVal*>* analyzed_records) const { return 1; }
|
||||
|
||||
// Bytes in total value object.
|
||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
||||
"GHI-572.")]] virtual unsigned int
|
||||
|
@ -255,6 +244,7 @@ protected:
|
|||
friend class EnumType;
|
||||
friend class ListVal;
|
||||
friend class RecordVal;
|
||||
friend class TableVal;
|
||||
friend class VectorVal;
|
||||
friend class ValManager;
|
||||
friend class TableEntryVal;
|
||||
|
@ -268,6 +258,21 @@ protected:
|
|||
|
||||
explicit Val(TypePtr t) noexcept : type(std::move(t)) { }
|
||||
|
||||
/**
|
||||
* Internal function for computing a Val's "footprint".
|
||||
*
|
||||
* @param analyzed_vals A pointer to a set used to track which values
|
||||
* have been analyzed to date, used to prevent infinite recursion.
|
||||
* The set should be empty (but not nil) on the first call.
|
||||
*
|
||||
* @return The total footprint.
|
||||
*/
|
||||
unsigned int Footprint(std::unordered_set<const Val*>* analyzed_vals) const;
|
||||
virtual unsigned int ComputeFootprint(std::unordered_set<const Val*>* analyzed_vals) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// For internal use by the Val::Clone() methods.
|
||||
struct CloneState
|
||||
{
|
||||
|
@ -691,13 +696,13 @@ public:
|
|||
|
||||
void Describe(ODesc* d) const override;
|
||||
|
||||
unsigned int Footprint(std::set<const RecordVal*>* analyzed_records) const override;
|
||||
|
||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
||||
"GHI-572.")]] unsigned int
|
||||
MemoryAllocation() const override;
|
||||
|
||||
protected:
|
||||
unsigned int ComputeFootprint(std::unordered_set<const Val*>* analyzed_vals) const override;
|
||||
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
|
||||
std::vector<ValPtr> vals;
|
||||
|
@ -968,8 +973,6 @@ public:
|
|||
// the function in the frame allowing it to capture its closure.
|
||||
void InitDefaultFunc(detail::Frame* f);
|
||||
|
||||
unsigned int Footprint(std::set<const RecordVal*>* analyzed_records) const override;
|
||||
|
||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
||||
"GHI-572.")]] unsigned int
|
||||
MemoryAllocation() const override;
|
||||
|
@ -1060,6 +1063,8 @@ protected:
|
|||
// Sends data on to backing Broker Store
|
||||
void SendToStore(const Val* index, const TableEntryVal* new_entry_val, OnChangeType tpe);
|
||||
|
||||
unsigned int ComputeFootprint(std::unordered_set<const Val*>* analyzed_vals) const override;
|
||||
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
|
||||
TableTypePtr table_type;
|
||||
|
@ -1396,8 +1401,6 @@ public:
|
|||
}
|
||||
RecordValPtr CoerceTo(RecordTypePtr other, bool allow_orphaning = false);
|
||||
|
||||
unsigned int Footprint(std::set<const RecordVal*>* analyzed_records) const override;
|
||||
|
||||
[[deprecated("Remove in v5.1. MemoryAllocation() is deprecated and will be removed. See "
|
||||
"GHI-572.")]] unsigned int
|
||||
MemoryAllocation() const override;
|
||||
|
@ -1470,6 +1473,8 @@ private:
|
|||
// Just for template inferencing.
|
||||
RecordVal* Get() { return this; }
|
||||
|
||||
unsigned int ComputeFootprint(std::unordered_set<const Val*>* analyzed_vals) const override;
|
||||
|
||||
// Keep this handy for quick access during low-level operations.
|
||||
RecordTypePtr rt;
|
||||
|
||||
|
@ -1655,8 +1660,6 @@ public:
|
|||
const auto& RawYieldType() const { return yield_type; }
|
||||
const auto& RawYieldTypes() const { return yield_types; }
|
||||
|
||||
unsigned int Footprint(std::set<const RecordVal*>* analyzed_records) const override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Returns the element at a given index or nullptr if it does not exist.
|
||||
|
@ -1670,6 +1673,9 @@ protected:
|
|||
ValPtr At(unsigned int index) const;
|
||||
|
||||
void ValDescribe(ODesc* d) const override;
|
||||
|
||||
unsigned int ComputeFootprint(std::unordered_set<const Val*>* analyzed_vals) const override;
|
||||
|
||||
ValPtr DoClone(CloneState* state) override;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue