diff --git a/CHANGES b/CHANGES index 3194fbdbf3..c0f62195b3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +6.2.0-dev.305 | 2024-01-03 09:38:17 +0000 + + * Avoid extra copies in threading_field_to_data (Dominik Charousset) + + Passing the `broker::data` paramter for `threading_field_to_data` by + value forces copies. However, the function only needs const access to + its parameter. Hence, taking the parameter as const-ref is the logical + choice and avoids unnecessary copies of individual data fields. + 6.2.0-dev.302 | 2024-01-02 11:13:17 -0700 * smb: Fix &read_expire not in effect due to &default=string_set() usage (Arne Welzel, Corelight) diff --git a/VERSION b/VERSION index 05df0a0187..f94329c18e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.2.0-dev.302 +6.2.0-dev.305 diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 4440bc6f5d..aa7928add8 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -1154,13 +1154,17 @@ broker::data threading_field_to_data(const threading::Field* f) { return broker::vector({name, secondary, type, subtype, optional}); } -threading::Field* data_to_threading_field(broker::data d) { +threading::Field* data_to_threading_field(const broker::data& d) { if ( ! holds_alternative(d) ) return nullptr; auto& v = get(d); + + if ( v.size() < 5 ) + return nullptr; + auto name = get_if(&v[0]); - auto secondary = v[1]; + const auto& secondary = v[1]; auto type = get_if(&v[2]); auto subtype = get_if(&v[3]); auto optional = get_if(&v[4]); diff --git a/src/broker/Data.h b/src/broker/Data.h index 2b91d404f6..4bdfe8e82c 100644 --- a/src/broker/Data.h +++ b/src/broker/Data.h @@ -101,7 +101,7 @@ broker::data threading_field_to_data(const threading::Field* f); * @return a pointer to a new zeek::threading::Value or a nullptr if the conversion was not * possible. */ -threading::Field* data_to_threading_field(broker::data d); +threading::Field* data_to_threading_field(const broker::data& d); /** * A Zeek value which wraps a Broker data value.