mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +00:00
Type: Add TypeManager->TypeList() and use for ListVal()
It turns out that for every ListVal we construct, we also allocate and construct a new TypeList instance, even though they are all the same. Pre-create and cache the type instances in a new TypeManager. The following script runs ~10% faster for me after this change. global tbl: table[string] of string; global i = 0; while ( ++i < 10000000 ) tbl["a"] = "a";
This commit is contained in:
parent
04a2ee7220
commit
24c606b4df
4 changed files with 36 additions and 4 deletions
16
src/Type.h
16
src/Type.h
|
@ -2,6 +2,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
@ -866,6 +867,21 @@ protected:
|
|||
TypePtr yield_type;
|
||||
};
|
||||
|
||||
// Holds pre-allocated Type objects.
|
||||
class TypeManager
|
||||
{
|
||||
public:
|
||||
TypeManager();
|
||||
|
||||
// Get a Typelist instance with the given type tag.
|
||||
const TypeListPtr& TypeList(TypeTag t) const;
|
||||
|
||||
private:
|
||||
std::array<TypeListPtr, NUM_TYPES> base_list_types;
|
||||
};
|
||||
|
||||
extern TypeManager* type_mgr;
|
||||
|
||||
// True if the two types are equivalent. If is_init is true then the test is
|
||||
// done in the context of an initialization. If match_record_field_names is
|
||||
// true then for record types the field names have to match, too.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue