RecordVal: Remove rt member

This doesn't seem to be really needed and costs 8 bytes per record value
This commit is contained in:
Arne Welzel 2025-09-27 17:41:26 +02:00
parent f30e0166a7
commit f17ca010bc
2 changed files with 24 additions and 26 deletions

View file

@ -2924,13 +2924,12 @@ TableVal::TableRecordDependencies TableVal::parse_time_table_record_dependencies
RecordVal::RecordTypeValMap RecordVal::parse_time_records;
RecordVal::RecordVal(RecordTypePtr t, bool init_fields) : Val(t) {
rt = std::move(t);
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.get()].emplace_back(NewRef{}, this);
parse_time_records[rt].emplace_back(NewRef{}, this);
if ( init_fields ) {
record_val.resize(n);
@ -2944,7 +2943,7 @@ RecordVal::RecordVal(RecordTypePtr t, bool init_fields) : Val(t) {
record_val[e.first] = e.second->Generate();
} catch ( InterpreterException& e ) {
if ( run_state::is_parsing )
parse_time_records[rt.get()].pop_back();
parse_time_records[rt].pop_back();
throw;
}
}
@ -2956,15 +2955,13 @@ RecordVal::RecordVal(RecordTypePtr t, bool init_fields) : Val(t) {
record_val.reserve(n);
}
RecordVal::RecordVal(RecordTypePtr t, std::vector<std::optional<ZVal>> init_vals) : Val(t) {
rt = std::move(t);
RecordVal::RecordVal(RecordTypePtr t, std::vector<std::optional<ZVal>> init_vals) : Val(std::move(t)) {
// TODO: Change so that callers pass init_vals as ZValSlot instead?
record_val.reserve(rt->NumFields());
size_t n = rt->NumFields();
size_t n = GetRecordType()->NumFields();
record_val.reserve(n);
for ( size_t i = 0; i < n; i++ ) {
record_val.emplace_back(ZValSlot(rt->GetFieldType(i)));
record_val.emplace_back(ZValSlot(GetRecordType()->GetFieldType(i)));
if ( init_vals[i].has_value() )
record_val[i] = init_vals[i].value();
@ -2977,7 +2974,7 @@ ValPtr RecordVal::SizeVal() const { return val_mgr->Count(GetType()->AsRecordTyp
void RecordVal::Assign(int field, ValPtr new_val) {
if ( new_val ) {
auto t = rt->GetFieldType(field);
const auto& t = GetRecordType()->GetFieldType(field);
record_val[field] = ZValSlot(new_val, t);
Modified();
}
@ -3105,7 +3102,7 @@ void RecordVal::Describe(ODesc* d) const {
auto n = record_val.size();
if ( d->IsBinary() ) {
rt->Describe(d);
GetRecordType()->Describe(d);
d->SP();
d->Add(static_cast<uint64_t>(n));
d->SP();
@ -3117,7 +3114,7 @@ void RecordVal::Describe(ODesc* d) const {
if ( ! d->IsBinary() && i > 0 )
d->Add(", ");
d->Add(rt->FieldName(i));
d->Add(GetRecordType()->FieldName(i));
if ( ! d->IsBinary() )
d->Add("=");
@ -3166,14 +3163,14 @@ ValPtr RecordVal::DoClone(CloneState* state) {
// record. As we cannot guarantee that it will be zeroed out at the
// appropriate time (as it seems to be guaranteed for the original record)
// we don't touch it.
auto rv = make_intrusive<RecordVal>(rt, false);
auto rv = make_intrusive<RecordVal>(GetType<zeek::RecordType>(), false);
state->NewClone(this, rv);
int n = NumFields();
for ( auto i = 0; i < n; ++i ) {
auto f_i = GetField(i);
auto v = f_i ? f_i->Clone(state) : nullptr;
rv->AppendField(std::move(v), rt->GetFieldType(i));
rv->AppendField(std::move(v), GetRecordType()->GetFieldType(i));
}
return rv;