Skip to content

Commit

Permalink
Merge branch 'topic/timw/move-bifs'
Browse files Browse the repository at this point in the history
* topic/timw/move-bifs:
  Use std::move in return values from bif methods to avoid copies
  Use bool return values instead of int in a couple zeek.bif static methods
  • Loading branch information
timwoj committed Jan 10, 2024
2 parents bddd74d + 010306f commit 2b4005b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 62 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
6.2.0-dev.347 | 2024-01-10 12:32:43 -0700

* Use std::move in return values from bif methods to avoid copies (Tim Wojtulewicz, Corelight)

* Use bool return values instead of int in a couple zeek.bif static methods (Tim Wojtulewicz, Corelight)

6.2.0-dev.344 | 2024-01-10 14:07:18 +0100

* quic: Handle and log unhandled_version (Arne Welzel, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.0-dev.344
6.2.0-dev.347
4 changes: 2 additions & 2 deletions src/reporter.bif
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function Reporter::get_weird_sampling_whitelist%(%): string_set
auto idx = zeek::make_intrusive<zeek::StringVal>(el);
set->Assign(std::move(idx), nullptr);
}
return set;
return std::move(set);
%}
## Sets the weird sampling whitelist
Expand Down Expand Up @@ -206,7 +206,7 @@ function Reporter::get_weird_sampling_global_list%(%): string_set
auto idx = zeek::make_intrusive<zeek::StringVal>(el);
set->Assign(std::move(idx), nullptr);
}
return set;
return std::move(set);
%}
## Sets the weird sampling global list
Expand Down
28 changes: 14 additions & 14 deletions src/stats.bif
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function get_net_stats%(%): NetStats
if ( stat.filtered )
r->Assign(n++, stat.filtered.value());

return r;
return std::move(r);
%}

## Returns Zeek traffic statistics.
Expand Down Expand Up @@ -107,7 +107,7 @@ function get_conn_stats%(%): ConnStats

r->Assign(n++, zeek::detail::killed_by_inactivity);

return r;
return std::move(r);
%}

## Returns Zeek process statistics.
Expand Down Expand Up @@ -164,7 +164,7 @@ function get_proc_stats%(%): ProcStats
r->Assign(n++, static_cast<uint64_t>(ru.ru_oublock));
r->Assign(n++, static_cast<uint64_t>(ru.ru_nivcsw));

return r;
return std::move(r);
%}

## Returns statistics about the event engine.
Expand All @@ -191,7 +191,7 @@ function get_event_stats%(%): EventStats
r->Assign(n++, event_mgr.num_events_queued);
r->Assign(n++, event_mgr.num_events_dispatched);

return r;
return std::move(r);
%}

## Returns statistics about reassembler usage.
Expand Down Expand Up @@ -221,7 +221,7 @@ function get_reassembler_stats%(%): ReassemblerStats
r->Assign(n++, Reassembler::MemoryAllocation(zeek::REASSEM_TCP));
r->Assign(n++, Reassembler::MemoryAllocation(zeek::REASSEM_UNKNOWN));

return r;
return std::move(r);
%}

## Returns statistics about DNS lookup activity.
Expand Down Expand Up @@ -257,7 +257,7 @@ function get_dns_stats%(%): DNSStats
r->Assign(n++, static_cast<uint64_t>(dstats.cached_texts));
r->Assign(n++, static_cast<uint64_t>(dstats.cached_total));

return r;
return std::move(r);
%}

## Returns statistics about timer usage.
Expand Down Expand Up @@ -285,7 +285,7 @@ function get_timer_stats%(%): TimerStats
r->Assign(n++, static_cast<uint64_t>(zeek::detail::timer_mgr->PeakSize()));
r->Assign(n++, static_cast<uint64_t>(zeek::detail::timer_mgr->CumulativeNum()));

return r;
return std::move(r);
%}

## Returns statistics about file analysis.
Expand Down Expand Up @@ -313,7 +313,7 @@ function get_file_analysis_stats%(%): FileAnalysisStats
r->Assign(n++, zeek::file_mgr->MaxFiles());
r->Assign(n++, zeek::file_mgr->CumulativeFiles());

return r;
return std::move(r);
%}

## Returns statistics about thread usage.
Expand All @@ -339,7 +339,7 @@ function get_thread_stats%(%): ThreadStats

r->Assign(n++, zeek::thread_mgr->NumThreads());

return r;
return std::move(r);
%}

## Returns statistics about TCP gaps.
Expand Down Expand Up @@ -368,7 +368,7 @@ function get_gap_stats%(%): GapStats
r->Assign(n++, zeek::detail::tot_gap_events);
r->Assign(n++, zeek::detail::tot_gap_bytes);

return r;
return std::move(r);
%}

## Returns statistics about the regular expression engine. Statistics include
Expand Down Expand Up @@ -408,7 +408,7 @@ function get_matcher_stats%(%): MatcherStats
r->Assign(n++, s.hits);
r->Assign(n++, s.misses);

return r;
return std::move(r);
%}

## Returns statistics about Broker communication.
Expand Down Expand Up @@ -444,7 +444,7 @@ function get_broker_stats%(%): BrokerStats
r->Assign(n++, static_cast<uint64_t>(cs.num_ids_incoming));
r->Assign(n++, static_cast<uint64_t>(cs.num_ids_outgoing));

return r;
return std::move(r);
%}

## Returns statistics about reporter messages and weirds.
Expand Down Expand Up @@ -479,7 +479,7 @@ function get_reporter_stats%(%): ReporterStats
r->Assign(n++, reporter->GetWeirdCount());
r->Assign(n++, std::move(weirds_by_type));

return r;
return std::move(r);
%}

## Returns statistics about calls to event handlers.
Expand All @@ -506,5 +506,5 @@ function get_event_handler_stats%(%): EventNameStats
}
}

return rval;
return std::move(rval);
%}
16 changes: 8 additions & 8 deletions src/strings.bif
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ function escape_string%(s: string%): string
char* escstr = s->AsString()->Render(zeek::String::ESC_HEX | zeek::String::ESC_ESC);
auto val = zeek::make_intrusive<zeek::StringVal>(escstr);
delete [] escstr;
return val;
return std::move(val);
%}
## Returns an ASCII hexadecimal representation of a string.
Expand Down Expand Up @@ -767,7 +767,7 @@ function str_smith_waterman%(s1: string, s2: string, params: sw_params%) : sw_su
zeek::util::delete_each(subseq);
delete subseq;
return result;
return std::move(result);
%}
## Splits a string into substrings with the help of an index vector of cutting
Expand Down Expand Up @@ -805,7 +805,7 @@ function str_split_indices%(s: string, idx: index_vec%): string_vec
delete result;
}
return result_v;
return std::move(result_v);
%}
## Strips whitespace at both ends of a string.
Expand Down Expand Up @@ -1021,7 +1021,7 @@ function find_all%(str: string, re: pattern, max_str_size: int &default=-1%) : s
auto a = zeek::make_intrusive<zeek::TableVal>(zeek::id::string_set);
if ( exceeds_max_string_length(str->Len(), max_str_size, frame) )
return a;
return std::move(a);
const u_char* s = str->Bytes();
const u_char* e = s + str->Len();
Expand All @@ -1037,7 +1037,7 @@ function find_all%(str: string, re: pattern, max_str_size: int &default=-1%) : s
}
}
return a;
return std::move(a);
%}
## Finds all occurrences of a pattern in a string. The order in which
Expand All @@ -1061,7 +1061,7 @@ function find_all_ordered%(str: string, re: pattern, max_str_size: int &default=
auto a = zeek::make_intrusive<zeek::VectorVal>(zeek::id::string_vec);
if ( exceeds_max_string_length(str->Len(), max_str_size, frame) )
return a;
return std::move(a);
const u_char* s = str->Bytes();
const u_char* e = s + str->Len();
Expand All @@ -1077,7 +1077,7 @@ function find_all_ordered%(str: string, re: pattern, max_str_size: int &default=
}
}
return a;
return std::move(a);
%}
## Finds the last occurrence of a pattern in a string. This function returns
Expand Down Expand Up @@ -1222,7 +1222,7 @@ function hexdump%(data_str: string%) : string
auto result = zeek::make_intrusive<zeek::StringVal>((const char*) hex_data);
delete [] hex_data;
return result;
return std::move(result);
%}
## Returns a reversed copy of the string
Expand Down
4 changes: 2 additions & 2 deletions src/supervisor/supervisor.bif
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ function Supervisor::__node%(%): Supervisor::NodeConfig
const auto& rt = zeek::BifType::Record::Supervisor::NodeConfig;
auto rval = zeek::make_intrusive<zeek::RecordVal>(rt);
rval->AssignField("name", "<invalid>");
return rval;
return std::move(rval);
}

auto rval = zeek::Supervisor::ThisNode()->config.ToRecord();
return rval;
return std::move(rval);
%}

function Supervisor::__is_supervisor%(%): bool
Expand Down
Loading

0 comments on commit 2b4005b

Please sign in to comment.