logging: Switch index-assignment of raw pointers to emplace_back()

This commit is contained in:
Arne Welzel 2024-08-30 10:04:26 +02:00
parent 245fd0c94f
commit a9290cc031
2 changed files with 10 additions and 6 deletions

View file

@ -1158,9 +1158,10 @@ bool Manager::WriteToFilters(const Manager::Stream* stream, zeek::RecordValPtr c
if ( zeek::plugin_mgr->HavePluginForHook(zeek::plugin::HOOK_LOG_WRITE) ) {
// The current HookLogWrite API takes a threading::Value**.
// Fabricate the pointer array on the fly. Mutation is allowed.
std::vector<threading::Value*> vals(rec.size());
for ( size_t i = 0; i < rec.size(); i++ )
vals[i] = &rec[i];
std::vector<threading::Value*> vals;
vals.reserve(rec.size());
for ( auto& v : rec )
vals.emplace_back(&v);
bool res =
zeek::plugin_mgr->HookLogWrite(filter->writer->GetType()->AsEnumType()->Lookup(

View file

@ -219,16 +219,19 @@ bool WriterBackend::Write(int arg_num_fields, zeek::Span<detail::LogRecord> reco
//
// We keep the raw pointer for this API, as threading::Value
// itself manages strings, sets and vectors using raw pointers,
// so this seems more consistent than mixing.
std::vector<Value*> valps(num_fields);
// so this is more consistent than mixing.
std::vector<Value*> valps;
valps.reserve(num_fields);
for ( size_t j = 0; j < records.size(); j++ ) {
auto& write_vals = records[j];
for ( int f = 0; f < num_fields; f++ )
valps[f] = &write_vals[f];
valps.emplace_back(&write_vals[f]);
success = DoWrite(num_fields, fields, &valps[0]);
valps.clear();
if ( ! success )
break;
}