mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 18:48:20 +00:00
Avoid extra copies in threading_field_to_data
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.
This commit is contained in:
parent
7a9a40f822
commit
12a45c2ff1
2 changed files with 7 additions and 3 deletions
|
@ -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<broker::vector>(d) )
|
||||
return nullptr;
|
||||
|
||||
auto& v = get<broker::vector>(d);
|
||||
|
||||
if ( v.size() < 5 )
|
||||
return nullptr;
|
||||
|
||||
auto name = get_if<std::string>(&v[0]);
|
||||
auto secondary = v[1];
|
||||
const auto& secondary = v[1];
|
||||
auto type = get_if<broker::count>(&v[2]);
|
||||
auto subtype = get_if<broker::count>(&v[3]);
|
||||
auto optional = get_if<broker::boolean>(&v[4]);
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue