From a9290cc0317bd1bcc6ae48056096db93494b0eb4 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Fri, 30 Aug 2024 10:04:26 +0200 Subject: [PATCH] logging: Switch index-assignment of raw pointers to emplace_back() --- src/logging/Manager.cc | 7 ++++--- src/logging/WriterBackend.cc | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 69a39822e7..ef5649c719 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -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 vals(rec.size()); - for ( size_t i = 0; i < rec.size(); i++ ) - vals[i] = &rec[i]; + std::vector vals; + vals.reserve(rec.size()); + for ( auto& v : rec ) + vals.emplace_back(&v); bool res = zeek::plugin_mgr->HookLogWrite(filter->writer->GetType()->AsEnumType()->Lookup( diff --git a/src/logging/WriterBackend.cc b/src/logging/WriterBackend.cc index e3b64c89aa..29ccde38cf 100644 --- a/src/logging/WriterBackend.cc +++ b/src/logging/WriterBackend.cc @@ -219,16 +219,19 @@ bool WriterBackend::Write(int arg_num_fields, zeek::Span 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 valps(num_fields); + // so this is more consistent than mixing. + std::vector 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; }