From e37baf09c0a392278239201e72c19103c53f150a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 8 Sep 2020 18:04:54 -0700 Subject: [PATCH] Improve Reporter weird-sampling-whitelist getters/setters - getter methods return const-ref - setter methods pass by value and std::move() - ranged-for loops over the whitelists access by const-ref --- src/Reporter.h | 12 ++++++------ src/reporter.bif | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Reporter.h b/src/Reporter.h index eaa357887a..f58bc6e068 100644 --- a/src/Reporter.h +++ b/src/Reporter.h @@ -175,7 +175,7 @@ public: /** * Gets the weird sampling whitelist. */ - WeirdSet GetWeirdSamplingWhitelist() const + const WeirdSet& GetWeirdSamplingWhitelist() const { return weird_sampling_whitelist; } @@ -185,15 +185,15 @@ public: * * @param weird_sampling_whitelist New weird sampling whitelist. */ - void SetWeirdSamplingWhitelist(const WeirdSet& weird_sampling_whitelist) + void SetWeirdSamplingWhitelist(WeirdSet weird_sampling_whitelist) { - this->weird_sampling_whitelist = weird_sampling_whitelist; + this->weird_sampling_whitelist = std::move(weird_sampling_whitelist); } /** * Gets the weird sampling global list. */ - WeirdSet GetWeirdSamplingGlobalList() const + const WeirdSet& GetWeirdSamplingGlobalList() const { return weird_sampling_global_list; } @@ -203,9 +203,9 @@ public: * * @param weird_sampling_global list New weird sampling global list. */ - void SetWeirdSamplingGlobalList(const WeirdSet& weird_sampling_global_list) + void SetWeirdSamplingGlobalList(WeirdSet weird_sampling_global_list) { - this->weird_sampling_global_list = weird_sampling_global_list; + this->weird_sampling_global_list = std::move(weird_sampling_global_list); } /** diff --git a/src/reporter.bif b/src/reporter.bif index 6ef94a346e..7f273e965a 100644 --- a/src/reporter.bif +++ b/src/reporter.bif @@ -164,7 +164,7 @@ function Reporter::file_weird%(name: string, f: fa_file, addl: string &default=" function Reporter::get_weird_sampling_whitelist%(%): string_set %{ auto set = zeek::make_intrusive(zeek::id::string_set); - for ( auto el : reporter->GetWeirdSamplingWhitelist() ) + for ( const auto& el : reporter->GetWeirdSamplingWhitelist() ) { auto idx = zeek::make_intrusive(el); set->Assign(std::move(idx), nullptr); @@ -194,7 +194,7 @@ function Reporter::set_weird_sampling_whitelist%(weird_sampling_whitelist: strin whitelist_set.emplace(move(key)); delete k; } - reporter->SetWeirdSamplingWhitelist(whitelist_set); + reporter->SetWeirdSamplingWhitelist(std::move(whitelist_set)); return zeek::val_mgr->True(); %} @@ -204,7 +204,7 @@ function Reporter::set_weird_sampling_whitelist%(weird_sampling_whitelist: strin function Reporter::get_weird_sampling_global_list%(%): string_set %{ auto set = zeek::make_intrusive(zeek::id::string_set); - for ( auto el : reporter->GetWeirdSamplingGlobalList() ) + for ( const auto& el : reporter->GetWeirdSamplingGlobalList() ) { auto idx = zeek::make_intrusive(el); set->Assign(std::move(idx), nullptr); @@ -234,7 +234,7 @@ function Reporter::set_weird_sampling_global_list%(weird_sampling_global_list: s global_list_set.emplace(move(key)); delete k; } - reporter->SetWeirdSamplingGlobalList(global_list_set); + reporter->SetWeirdSamplingGlobalList(std::move(global_list_set)); return zeek::val_mgr->True(); %}