Adjust memory management for &default argument expression type-check

Mainly, there was an extra Ref().  In theory, the front-insertion was
also not efficient.
This commit is contained in:
Jon Siwek 2021-01-13 15:16:52 -08:00
parent fe8db7f150
commit d4ae5c5fbc

View file

@ -5277,7 +5277,7 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types)
if ( el.length() < ntypes ) if ( el.length() < ntypes )
{ {
ExprPList def_elements; std::vector<ExprPtr> def_elements;
// Start from rightmost parameter, work backward to fill in missing // Start from rightmost parameter, work backward to fill in missing
// arguments using &default expressions. // arguments using &default expressions.
@ -5300,12 +5300,13 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types)
// separately for each instance, rather than // separately for each instance, rather than
// one instance inheriting the transformed version // one instance inheriting the transformed version
// from another. // from another.
auto e = def_attr->GetExpr(); const auto& e = def_attr->GetExpr();
def_elements.push_front(e->Duplicate().release()); def_elements.emplace_back(e->Duplicate());
} }
for ( const auto& elem : def_elements ) auto ne = def_elements.size();
el.push_back(elem->Ref()); while ( ne )
el.push_back(def_elements[--ne].release());
} }
TypeList* tl = new TypeList(); TypeList* tl = new TypeList();