mirror of
https://github.com/zeek/zeek.git
synced 2025-10-01 22:28:20 +00:00
Modifiable: No virtual destructor
There's only three classes that inherit from Modifiable today. The virtual destructor adds an extra 8 byte vtable to every instance of table, record or vector values. Calling Unregister() explicitly from the destructors explicitly saves 8 bytes of memory for each instance.
This commit is contained in:
parent
5e9dad04db
commit
00ad3e31c6
3 changed files with 18 additions and 7 deletions
|
@ -62,9 +62,4 @@ void Registry::Terminate() {
|
|||
}
|
||||
}
|
||||
|
||||
Modifiable::~Modifiable() {
|
||||
if ( num_receivers )
|
||||
registry.Unregister(this);
|
||||
}
|
||||
|
||||
} // namespace zeek::notifier::detail
|
||||
|
|
|
@ -99,8 +99,6 @@ extern Registry registry;
|
|||
*/
|
||||
class Modifiable {
|
||||
public:
|
||||
virtual ~Modifiable();
|
||||
|
||||
/**
|
||||
* Calling this method signals to all registered receivers that the
|
||||
* object has been modified.
|
||||
|
@ -110,6 +108,17 @@ public:
|
|||
registry.Modified(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister this instance from the registry.
|
||||
*
|
||||
* Classes inheriting from Modifiable are required to call
|
||||
* this from the destructor explicitly.
|
||||
*/
|
||||
void Unregister() {
|
||||
if ( num_receivers )
|
||||
registry.Unregister(this);
|
||||
}
|
||||
|
||||
protected:
|
||||
friend class Registry;
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "zeek/IPAddr.h"
|
||||
#include "zeek/IntrusivePtr.h"
|
||||
#include "zeek/NetVar.h"
|
||||
#include "zeek/Notifier.h"
|
||||
#include "zeek/Overflow.h"
|
||||
#include "zeek/PrefixTable.h"
|
||||
#include "zeek/RE.h"
|
||||
|
@ -1712,6 +1713,8 @@ void TableVal::Init(TableTypePtr t, bool ordered) {
|
|||
}
|
||||
|
||||
TableVal::~TableVal() {
|
||||
notifier::detail::Modifiable::Unregister();
|
||||
|
||||
if ( timer )
|
||||
detail::timer_mgr->Cancel(timer);
|
||||
|
||||
|
@ -2952,6 +2955,8 @@ RecordVal::RecordVal(RecordTypePtr t, std::vector<std::optional<ZVal>> init_vals
|
|||
}
|
||||
|
||||
RecordVal::~RecordVal() {
|
||||
notifier::detail::Modifiable::Unregister();
|
||||
|
||||
auto n = record_val.size();
|
||||
|
||||
for ( unsigned int i = 0; i < n; ++i ) {
|
||||
|
@ -3234,6 +3239,8 @@ VectorVal::VectorVal(VectorTypePtr t, std::vector<std::optional<ZVal>>* vals) :
|
|||
}
|
||||
|
||||
VectorVal::~VectorVal() {
|
||||
notifier::detail::Modifiable::Unregister();
|
||||
|
||||
if ( yield_types ) {
|
||||
int n = yield_types->size();
|
||||
for ( auto i = 0; i < n; ++i ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue