mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
RecordVal: Avoid intermediate ZValElement during init
ZValElement(TypeDecl) would first construct a ZValElement, then use the assignment operator for the ZValElement. Switch to support assigning a TypeDecl to a ZValElement for initialization purposes directly.
This commit is contained in:
parent
07ddc34ae4
commit
111893d31f
1 changed files with 16 additions and 6 deletions
22
src/Val.h
22
src/Val.h
|
@ -1153,11 +1153,6 @@ public:
|
|||
ZValElement(ValPtr v, const TypePtr& t)
|
||||
: is_set(true), is_managed(ZVal::IsManagedType(t)), tag(t->Tag()), zval(v, t) {}
|
||||
|
||||
/**
|
||||
* Initialize a ZValElement using a TypeDecl.
|
||||
*/
|
||||
ZValElement(const TypeDecl& td) : is_managed(td.is_managed), tag(td.tag) {}
|
||||
|
||||
/**
|
||||
* Initialize a ZValElement with just the TypePtr.
|
||||
*
|
||||
|
@ -1223,6 +1218,21 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a ZValElement using a TypeDecl assignment.
|
||||
*
|
||||
* This is used at record construction time to set the is_managed
|
||||
* and tag fields properly.
|
||||
*/
|
||||
const ZValElement& operator=(const TypeDecl& td) noexcept {
|
||||
assert(! IsSet());
|
||||
assert(tag == TYPE_ERROR);
|
||||
is_managed = td.is_managed;
|
||||
tag = td.tag;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
operator bool() const noexcept { return is_set; }
|
||||
const ZVal* operator->() const noexcept { return &zval; }
|
||||
ZVal& operator*() noexcept { return zval; }
|
||||
|
@ -1662,7 +1672,7 @@ private:
|
|||
size_t n = NumFields();
|
||||
assert(n == rt->Types()->size());
|
||||
for ( size_t i = 0; i < n; i++ )
|
||||
elements[i] = ZValElement(*rt->FieldDecl(i));
|
||||
elements[i] = *rt->FieldDecl(i);
|
||||
}
|
||||
|
||||
unsigned int ComputeFootprint(std::unordered_set<const Val*>* analyzed_vals) const override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue