RecordVal: Avoid IsManagedType() calls during construction

This commit is contained in:
Arne Welzel 2025-09-29 11:34:09 +02:00
parent 108e9fca4c
commit e595dbc9bf
2 changed files with 8 additions and 6 deletions

View file

@ -2926,17 +2926,14 @@ RecordVal::RecordTypeValMap RecordVal::parse_time_records;
RecordVal::RecordVal(RecordTypePtr t, bool init_fields) : Val(std::move(t)) {
auto* rt = GetRecordType();
int n = rt->NumFields();
if ( run_state::is_parsing )
parse_time_records[rt].emplace_back(NewRef{}, this);
if ( init_fields ) {
record_val.resize(n);
record_val.resize(rt->NumFields());
// Properly initialize all slots.
for ( size_t i = 0; i < record_val.size(); i++ )
record_val[i] = ZValSlot(rt->GetFieldType(i));
rt->InitSlots(record_val);
for ( auto& e : rt->CreationInits() ) {
try {
@ -2952,7 +2949,7 @@ RecordVal::RecordVal(RecordTypePtr t, bool init_fields) : Val(std::move(t)) {
else
// This needs to go through AppendField() which will do the right thing
// for the individual slots.
record_val.reserve(n);
record_val.reserve(rt->NumFields());
}
RecordVal::RecordVal(RecordTypePtr t, std::vector<std::optional<ZVal>> init_vals) : Val(std::move(t)) {

View file

@ -1147,6 +1147,11 @@ public:
ZValSlot(ValPtr v, const TypePtr& t)
: is_set(true), is_managed(ZVal::IsManagedType(t)), type_tag(t->Tag()), zval(v, t) {}
/**
* Initialize a ZValSlot using its properties.
*/
ZValSlot(const RecordFieldProperties p) : is_set(false), is_managed(p.is_managed), type_tag(p.type_tag) {}
/**
* Initialize a ZValSlot with just the TypePtr.
*