mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 00:58:19 +00:00
Optimize initial memory consumption
This commit is contained in:
parent
eb08b696bf
commit
3f349b8a37
10 changed files with 49 additions and 22 deletions
21
src/Val.cc
21
src/Val.cc
|
@ -3963,17 +3963,9 @@ ValManager::ValManager()
|
|||
for ( auto i = 0u; i < PREALLOCATED_INTS; ++i )
|
||||
ints[i] = Val::MakeInt(PREALLOCATED_INT_LOWEST + i);
|
||||
|
||||
for ( auto i = 0u; i < ports.size(); ++i )
|
||||
{
|
||||
auto& arr = ports[i];
|
||||
auto port_type = (TransportProto)i;
|
||||
|
||||
for ( auto j = 0u; j < arr.size(); ++j )
|
||||
arr[j] = IntrusivePtr{AdoptRef{}, new PortVal(PortVal::Mask(j, port_type))};
|
||||
}
|
||||
}
|
||||
|
||||
const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type) const
|
||||
const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type)
|
||||
{
|
||||
if ( port_num >= 65536 )
|
||||
{
|
||||
|
@ -3981,10 +3973,17 @@ const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type)
|
|||
port_num = 0;
|
||||
}
|
||||
|
||||
return ports[port_type][port_num];
|
||||
|
||||
std::pair key{port_num, port_type};
|
||||
if (ports.find(key) == ports.end())
|
||||
{
|
||||
ports[key] = IntrusivePtr{AdoptRef{}, new PortVal(PortVal::Mask(port_num, port_type))};
|
||||
}
|
||||
|
||||
const PortValPtr& ValManager::Port(uint32_t port_num) const
|
||||
return ports[key];
|
||||
}
|
||||
|
||||
const PortValPtr& ValManager::Port(uint32_t port_num)
|
||||
{
|
||||
auto mask = port_num & PORT_SPACE_MASK;
|
||||
port_num &= ~PORT_SPACE_MASK;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue