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:
Arne Welzel 2023-03-30 19:36:26 +02:00
parent 04a2ee7220
commit 24c606b4df
4 changed files with 36 additions and 4 deletions

View file

@ -1188,10 +1188,7 @@ ValPtr PatternVal::DoClone(CloneState* state)
return state->NewClone(this, make_intrusive<PatternVal>(re));
}
ListVal::ListVal(TypeTag t) : Val(make_intrusive<TypeList>(t == TYPE_ANY ? nullptr : base_type(t)))
{
tag = t;
}
ListVal::ListVal(TypeTag t) : Val(type_mgr->TypeList(t)), tag(t) { }
ListVal::~ListVal() { }