avoid constructing TypeList's on-the-fly for ListVal's with fixed types

This commit is contained in:
Vern Paxson 2023-07-13 11:47:14 -07:00
parent 1d5bc841e0
commit 6b0d595dae
3 changed files with 16 additions and 3 deletions

View file

@ -5029,7 +5029,7 @@ bool ListExpr::IsPure() const
ValPtr ListExpr::Eval(Frame* f) const
{
auto v = make_intrusive<ListVal>(TYPE_ANY);
std::vector<ValPtr> evs;
for ( const auto& expr : exprs )
{
@ -5041,10 +5041,10 @@ ValPtr ListExpr::Eval(Frame* f) const
return nullptr;
}
v->Append(std::move(ev));
evs.push_back(std::move(ev));
}
return v;
return make_intrusive<ListVal>(cast_intrusive<TypeList>(type), std::move(evs));
}
TypePtr ListExpr::InitType() const

View file

@ -1563,6 +1563,12 @@ ListVal::ListVal(TypeTag t) : Val(make_intrusive<TypeList>(t == TYPE_ANY ? nullp
tag = t;
}
ListVal::ListVal(TypeListPtr tl, std::vector<ValPtr> _vals) : Val(std::move(tl))
{
tag = TYPE_ANY;
vals = std::move(_vals);
}
ValPtr ListVal::SizeVal() const
{
return val_mgr->Count(vals.size());

View file

@ -661,8 +661,15 @@ private:
class ListVal final : public Val
{
public:
// Constructor used to build up a homogeneous list of values;
// or, if 't' is TYPE_ANY, then a heterogeneous one whose type
// is built up as values are appended.
explicit ListVal(TypeTag t);
// Constructor used to build the list in one shot, with the type
// pre-computed.
ListVal(TypeListPtr tl, std::vector<ValPtr> vals);
~ListVal() override = default;
TypeTag BaseTag() const { return tag; }