UpdateConnVal: Avoid FieldOffset() calls

These can be significant if a lot of new connections and or events
are created for which an existing conn val needs updating and otherwise
things are very fast.
This commit is contained in:
Arne Welzel 2023-12-02 23:21:09 +01:00
parent c3762ba9d3
commit 01e305edd8
2 changed files with 13 additions and 15 deletions

View file

@ -1027,8 +1027,11 @@ void TCPSessionAdapter::FlipRoles() {
}
void TCPSessionAdapter::UpdateConnVal(RecordVal* conn_val) {
auto orig_endp_val = conn_val->GetFieldAs<RecordVal>("orig");
auto resp_endp_val = conn_val->GetFieldAs<RecordVal>("resp");
static const auto& conn_type = zeek::id::find_type<zeek::RecordType>("connection");
static const int origidx = conn_type->FieldOffset("orig");
static const int respidx = conn_type->FieldOffset("resp");
auto* orig_endp_val = conn_val->GetFieldAs<RecordVal>(origidx);
auto* resp_endp_val = conn_val->GetFieldAs<RecordVal>(respidx);
orig_endp_val->Assign(0, orig->Size());
orig_endp_val->Assign(1, orig->state);