From e595dbc9bffb71025c9bb044ff9b314a837b4273 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Mon, 29 Sep 2025 11:34:09 +0200 Subject: [PATCH] RecordVal: Avoid IsManagedType() calls during construction --- src/Val.cc | 9 +++------ src/Val.h | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index dc8ab0c420..9eb0ef1c2a 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -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> init_vals) : Val(std::move(t)) { diff --git a/src/Val.h b/src/Val.h index 74b244cdf4..3dd1293c06 100644 --- a/src/Val.h +++ b/src/Val.h @@ -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. *