From: Gunnar Beutner Date: Thu, 30 Nov 2017 07:19:58 +0000 (+0100) Subject: Use std::vector::emplace_back instead of std::vector::push_back X-Git-Tag: v2.9.0~310^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c60fbf75ddd89c618b535e8dab0902c9049d724;p=icinga2 Use std::vector::emplace_back instead of std::vector::push_back --- diff --git a/lib/base/array-script.cpp b/lib/base/array-script.cpp index dd9d5628d..54fb394ec 100644 --- a/lib/base/array-script.cpp +++ b/lib/base/array-script.cpp @@ -77,10 +77,7 @@ static void ArrayClear(void) static bool ArraySortCmp(const Function::Ptr& cmp, const Value& a, const Value& b) { - std::vector args; - args.push_back(a); - args.push_back(b); - return cmp->Invoke(args); + return cmp->Invoke({ a, b }); } static Array::Ptr ArraySort(const std::vector& args) @@ -154,9 +151,7 @@ static Array::Ptr ArrayMap(const Function::Ptr& function) ObjectLock olock(self); for (const Value& item : self) { - std::vector args; - args.push_back(item); - result->Add(function->Invoke(args)); + result->Add(function->Invoke({ item })); } return result; @@ -177,10 +172,7 @@ static Value ArrayReduce(const Function::Ptr& function) ObjectLock olock(self); for (size_t i = 1; i < self->GetLength(); i++) { - std::vector args; - args.push_back(result); - args.push_back(self->Get(i)); - result = function->Invoke(args); + result = function->Invoke({ result, self->Get(i) }); } return result; @@ -198,9 +190,7 @@ static Array::Ptr ArrayFilter(const Function::Ptr& function) ObjectLock olock(self); for (const Value& item : self) { - std::vector args; - args.push_back(item); - if (function->Invoke(args)) + if (function->Invoke({ item })) result->Add(item); } @@ -217,9 +207,7 @@ static bool ArrayAny(const Function::Ptr& function) ObjectLock olock(self); for (const Value& item : self) { - std::vector args; - args.push_back(item); - if (function->Invoke(args)) + if (function->Invoke({ item })) return true; } @@ -236,9 +224,7 @@ static bool ArrayAll(const Function::Ptr& function) ObjectLock olock(self); for (const Value& item : self) { - std::vector args; - args.push_back(item); - if (!function->Invoke(args)) + if (!function->Invoke({ item })) return false; } diff --git a/lib/base/array.cpp b/lib/base/array.cpp index 243f88ecd..a493e8177 100644 --- a/lib/base/array.cpp +++ b/lib/base/array.cpp @@ -90,7 +90,7 @@ void Array::Add(Value&& value) { ObjectLock olock(this); - m_Data.push_back(std::move(value)); + m_Data.emplace_back(std::move(value)); } /** diff --git a/lib/base/function-script.cpp b/lib/base/function-script.cpp index 09e85939d..2df59cc37 100644 --- a/lib/base/function-script.cpp +++ b/lib/base/function-script.cpp @@ -34,7 +34,7 @@ static Value FunctionCall(const std::vector& args) Function::Ptr self = static_cast(vframe->Self); std::vector uargs(args.begin() + 1, args.end()); - return self->Invoke(args[0], uargs); + return self->InvokeThis(args[0], uargs); } static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args) @@ -49,7 +49,7 @@ static Value FunctionCallV(const Value& thisArg, const Array::Ptr& args) uargs = std::vector(args->Begin(), args->End()); } - return self->Invoke(thisArg, uargs); + return self->InvokeThis(thisArg, uargs); } diff --git a/lib/base/function.cpp b/lib/base/function.cpp index 8cc233774..cb34d835f 100644 --- a/lib/base/function.cpp +++ b/lib/base/function.cpp @@ -42,7 +42,7 @@ Value Function::Invoke(const std::vector& arguments) return m_Callback(arguments); } -Value Function::Invoke(const Value& otherThis, const std::vector& arguments) +Value Function::InvokeThis(const Value& otherThis, const std::vector& arguments) { ScriptFrame frame; frame.Self = otherThis; diff --git a/lib/base/function.hpp b/lib/base/function.hpp index 6f257863f..6dc070080 100644 --- a/lib/base/function.hpp +++ b/lib/base/function.hpp @@ -49,7 +49,7 @@ public: { } Value Invoke(const std::vector& arguments = std::vector()); - Value Invoke(const Value& otherThis, const std::vector& arguments = std::vector()); + Value InvokeThis(const Value& otherThis, const std::vector& arguments = std::vector()); inline bool IsSideEffectFree(void) const { diff --git a/lib/base/socketevents-epoll.cpp b/lib/base/socketevents-epoll.cpp index dadd40117..589fe789a 100644 --- a/lib/base/socketevents-epoll.cpp +++ b/lib/base/socketevents-epoll.cpp @@ -116,7 +116,7 @@ void SocketEventEngineEpoll::ThreadProc(int tid) event.LifesupportReference = event.Descriptor.LifesupportObject; VERIFY(event.LifesupportReference); - events.push_back(event); + events.emplace_back(std::move(event)); } } diff --git a/lib/base/socketevents-poll.cpp b/lib/base/socketevents-poll.cpp index d141abe95..3c9539cf0 100644 --- a/lib/base/socketevents-poll.cpp +++ b/lib/base/socketevents-poll.cpp @@ -108,7 +108,7 @@ void SocketEventEnginePoll::ThreadProc(int tid) event.LifesupportReference = event.Descriptor.LifesupportObject; VERIFY(event.LifesupportReference); - events.push_back(event); + events.emplace_back(std::move(event)); } } diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index 8b9b4705c..683a6b6dd 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -212,7 +212,7 @@ bool ThreadPool::Post(const ThreadPool::WorkFunction& callback, SchedulerPolicy if (policy == LowLatencyScheduler) queue.SpawnWorker(m_ThreadGroup); - queue.Items.push_back(wi); + queue.Items.emplace_back(std::move(wi)); queue.CV.notify_one(); } diff --git a/lib/base/typetype-script.cpp b/lib/base/typetype-script.cpp index 66452fdcc..21ef5d572 100644 --- a/lib/base/typetype-script.cpp +++ b/lib/base/typetype-script.cpp @@ -28,9 +28,7 @@ using namespace icinga; static void InvokeAttributeHandlerHelper(const Function::Ptr& callback, const Object::Ptr& object, const Value& cookie) { - std::vector arguments; - arguments.push_back(object); - callback->Invoke(arguments); + callback->Invoke({ object }); } static void TypeRegisterAttributeHandler(const String& fieldName, const Function::Ptr& callback) diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index ce6aa572d..fddc40cfc 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -976,31 +976,31 @@ String Utility::FormatDuration(double duration) if (duration >= 86400) { int days = duration / 86400; - tokens.push_back(Convert::ToString(days) + (days != 1 ? " days" : " day")); + tokens.emplace_back(Convert::ToString(days) + (days != 1 ? " days" : " day")); duration = static_cast(duration) % 86400; } if (duration >= 3600) { int hours = duration / 3600; - tokens.push_back(Convert::ToString(hours) + (hours != 1 ? " hours" : " hour")); + tokens.emplace_back(Convert::ToString(hours) + (hours != 1 ? " hours" : " hour")); duration = static_cast(duration) % 3600; } if (duration >= 60) { int minutes = duration / 60; - tokens.push_back(Convert::ToString(minutes) + (minutes != 1 ? " minutes" : " minute")); + tokens.emplace_back(Convert::ToString(minutes) + (minutes != 1 ? " minutes" : " minute")); duration = static_cast(duration) % 60; } if (duration >= 1) { int seconds = duration; - tokens.push_back(Convert::ToString(seconds) + (seconds != 1 ? " seconds" : " second")); + tokens.emplace_back(Convert::ToString(seconds) + (seconds != 1 ? " seconds" : " second")); } if (tokens.size() == 0) { int milliseconds = std::floor(duration * 1000); if (milliseconds >= 1) - tokens.push_back(Convert::ToString(milliseconds) + (milliseconds != 1 ? " milliseconds" : " millisecond")); + tokens.emplace_back(Convert::ToString(milliseconds) + (milliseconds != 1 ? " milliseconds" : " millisecond")); else tokens.push_back("less than 1 millisecond"); } diff --git a/lib/cli/apisetuputility.cpp b/lib/cli/apisetuputility.cpp index b658f9339..4186475d8 100644 --- a/lib/cli/apisetuputility.cpp +++ b/lib/cli/apisetuputility.cpp @@ -132,16 +132,7 @@ bool ApiSetupUtility::SetupMasterCertificates(const String& cn) Utility::CopyFile(ca, target_ca); /* fix permissions: root -> icinga daemon user */ - std::vector files; - files.push_back(ca_path); - files.push_back(ca); - files.push_back(ca_key); - files.push_back(target_ca); - files.push_back(key); - files.push_back(csr); - files.push_back(cert); - - for (const String& file : files) { + for (const String& file : { ca_path, ca, ca_key, target_ca, key, csr, cert }) { if (!Utility::SetFileOwnership(file, user, group)) { Log(LogWarning, "cli") << "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << file << "'."; @@ -201,9 +192,7 @@ bool ApiSetupUtility::SetupMasterEnableApi(void) { Log(LogInformation, "cli", "Enabling the 'api' feature."); - std::vector features; - features.push_back("api"); - FeatureUtility::EnableFeatures(features); + FeatureUtility::EnableFeatures({ "api" }); return true; } diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index 6459fe2fb..e9d0d60d6 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -234,7 +234,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector configs; if (vm.count("config") > 0) - configs = vm["config"].as < std::vector >() ; + configs = vm["config"].as >(); else if (!vm.count("no-config")) configs.push_back(Application::GetSysconfDir() + "/icinga2/icinga2.conf"); diff --git a/lib/cli/troubleshootcommand.cpp b/lib/cli/troubleshootcommand.cpp index a8e5d4b42..28ea6cb72 100644 --- a/lib/cli/troubleshootcommand.cpp +++ b/lib/cli/troubleshootcommand.cpp @@ -444,10 +444,7 @@ bool TroubleshootCommand::PrintFile(InfoLog& log, const String& path) bool TroubleshootCommand::CheckConfig(void) { - std::vector configs; - configs.push_back(Application::GetSysconfDir() + "/icinga2/icinga2.conf"); - - return DaemonUtility::ValidateConfigFiles(configs, Application::GetObjectsPath()); + return DaemonUtility::ValidateConfigFiles({ Application::GetSysconfDir() + "/icinga2/icinga2.conf" }, Application::GetObjectsPath()); } //print is supposed allow the user to print the object file diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index d67258035..ec9c7c8c9 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -634,8 +634,8 @@ void StatusDataWriter::UpdateObjectsCache(void) for (const Service::Ptr& service : sg->GetMembers()) { Host::Ptr host = service->GetHost(); - sglist.push_back(host->GetName()); - sglist.push_back(service->GetShortName()); + sglist.emplace_back(host->GetName()); + sglist.emplace_back(service->GetShortName()); } DumpStringList(tempobjectfp, sglist); @@ -734,15 +734,15 @@ void StatusDataWriter::UpdateObjectsCache(void) int state_filter = dep->GetStateFilter(); std::vector failure_criteria; if (state_filter & StateFilterOK || state_filter & StateFilterUp) - failure_criteria.push_back("o"); + failure_criteria.emplace_back("o"); if (state_filter & StateFilterWarning) - failure_criteria.push_back("w"); + failure_criteria.emplace_back("w"); if (state_filter & StateFilterCritical) - failure_criteria.push_back("c"); + failure_criteria.emplace_back("c"); if (state_filter & StateFilterUnknown) - failure_criteria.push_back("u"); + failure_criteria.emplace_back("u"); if (state_filter & StateFilterDown) - failure_criteria.push_back("d"); + failure_criteria.emplace_back("d"); String criteria = boost::algorithm::join(failure_criteria, ","); diff --git a/lib/config/config_parser.yy b/lib/config/config_parser.yy index 36f972410..688429a53 100644 --- a/lib/config/config_parser.yy +++ b/lib/config/config_parser.yy @@ -328,13 +328,13 @@ lterm_items_inner: lterm %dprec 2 { $$ = new std::vector >(); EItemInfo info = { true, @1 }; - $$->push_back(std::make_pair($1, info)); + $$->emplace_back($1, info); } | rterm_no_side_effect { $$ = new std::vector >(); EItemInfo info = { false, @1 }; - $$->push_back(std::make_pair($1, info)); + $$->emplace_back($1, info); } | lterm_items_inner sep lterm %dprec 1 { @@ -345,7 +345,7 @@ lterm_items_inner: lterm %dprec 2 if ($3) { EItemInfo info = { true, @3 }; - $$->push_back(std::make_pair($3, info)); + $$->emplace_back($3, info); } } | lterm_items_inner sep rterm_no_side_effect %dprec 1 @@ -357,7 +357,7 @@ lterm_items_inner: lterm %dprec 2 if ($3) { EItemInfo info = { false, @3 }; - $$->push_back(std::make_pair($3, info)); + $$->emplace_back($3, info); } } ; diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 0ab2a0712..edb0527ba 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -404,7 +404,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue if (kv2.second->m_ActivationContext != context) continue; - items.push_back(std::make_pair(kv2.second, false)); + items.emplace_back(kv2.second, false); } } @@ -419,7 +419,7 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue if (item->m_Abstract || item->m_Object) continue; - items.push_back(std::make_pair(item, true)); + items.emplace_back(item, true); } m_UnnamedItems.swap(newUnnamedItems); diff --git a/lib/config/vmops.hpp b/lib/config/vmops.hpp index 193a57ab5..4376f32d7 100644 --- a/lib/config/vmops.hpp +++ b/lib/config/vmops.hpp @@ -102,7 +102,7 @@ public: static inline Value FunctionCall(ScriptFrame& frame, const Value& self, const Function::Ptr& func, const std::vector& arguments) { if (!self.IsEmpty() || self.IsString()) - return func->Invoke(self, arguments); + return func->InvokeThis(self, arguments); else return func->Invoke(arguments); diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index 96a744fdc..a9b189ade 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -181,13 +181,12 @@ void DbConnection::UpdateProgramStatus(void) query1.Fields->Set("process_performance_data", (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0)); query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ - query1.Priority = PriorityHigh; - queries.push_back(query1); + queries.emplace_back(std::move(query1)); DbQuery query2; query2.Type = DbQueryNewTransaction; - queries.push_back(query2); + queries.emplace_back(std::move(query2)); DbObject::OnMultipleQueries(queries); diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index b14b19ce6..d67901c90 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -383,8 +383,7 @@ void DbEvents::AddCommentInternal(std::vector& queries, const Comment:: } query1.Category = DbCatComment; query1.Fields = fields1; - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); } void DbEvents::RemoveComment(const Comment::Ptr& comment) @@ -409,7 +408,7 @@ void DbEvents::RemoveCommentInternal(std::vector& queries, const Commen query1.WhereCriteria->Set("object_id", checkable); query1.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); query1.WhereCriteria->Set("name", comment->GetName()); - queries.push_back(query1); + queries.emplace_back(std::move(query1)); /* History - update deletion time for service/host */ double now = Utility::GetTime(); @@ -429,7 +428,7 @@ void DbEvents::RemoveCommentInternal(std::vector& queries, const Commen query2.WhereCriteria->Set("object_id", checkable); query2.WhereCriteria->Set("entry_time", DbValue::FromTimestamp(entry_time)); query2.WhereCriteria->Set("name", comment->GetName()); - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } /* downtimes */ @@ -526,8 +525,7 @@ void DbEvents::AddDowntimeInternal(std::vector& queries, const Downtime query1.Category = DbCatDowntime; query1.Fields = fields1; - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); /* host/service status */ if (!historical) { @@ -558,8 +556,7 @@ void DbEvents::AddDowntimeInternal(std::vector& queries, const Downtime query2.WhereCriteria->Set("host_object_id", host); query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } } @@ -587,7 +584,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt query1.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); query1.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); query1.WhereCriteria->Set("name", downtime->GetName()); - queries.push_back(query1); + queries.emplace_back(std::move(query1)); /* History - update actual_end_time, was_cancelled for service (and host in case) */ double now = Utility::GetTime(); @@ -616,8 +613,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt query3.WhereCriteria->Set("scheduled_start_time", DbValue::FromTimestamp(downtime->GetStartTime())); query3.WhereCriteria->Set("scheduled_end_time", DbValue::FromTimestamp(downtime->GetEndTime())); query3.WhereCriteria->Set("name", downtime->GetName()); - - queries.push_back(query3); + queries.emplace_back(std::move(query3)); /* host/service status */ Host::Ptr host; @@ -647,8 +643,7 @@ void DbEvents::RemoveDowntimeInternal(std::vector& queries, const Downt query4.WhereCriteria->Set("host_object_id", host); query4.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ - - queries.push_back(query4); + queries.emplace_back(std::move(query4)); } void DbEvents::TriggerDowntime(const Downtime::Ptr& downtime) @@ -908,7 +903,7 @@ void DbEvents::AddNotificationHistory(const Notification::Ptr& notification, con fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.Fields = fields2; - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } DbObject::OnMultipleQueries(queries); diff --git a/lib/db_ido/dbobject.cpp b/lib/db_ido/dbobject.cpp index a40e7d775..a606a2e67 100644 --- a/lib/db_ido/dbobject.cpp +++ b/lib/db_ido/dbobject.cpp @@ -217,8 +217,7 @@ void DbObject::SendVarsConfigUpdateHeavy(void) query1.Category = DbCatConfig; query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("object_id", obj); - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); DbQuery query2; query2.Table = "customvariablestatus"; @@ -226,8 +225,7 @@ void DbObject::SendVarsConfigUpdateHeavy(void) query2.Category = DbCatConfig; query2.WhereCriteria = new Dictionary(); query2.WhereCriteria->Set("object_id", obj); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object); @@ -260,8 +258,7 @@ void DbObject::SendVarsConfigUpdateHeavy(void) query3.Type = DbQueryInsert; query3.Category = DbCatConfig; query3.Fields = fields; - - queries.push_back(query3); + queries.emplace_back(std::move(query3)); } } @@ -313,8 +310,7 @@ void DbObject::SendVarsStatusUpdate(void) query.WhereCriteria = new Dictionary(); query.WhereCriteria->Set("object_id", obj); query.WhereCriteria->Set("varname", kv.first); - - queries.push_back(query); + queries.emplace_back(std::move(query)); } OnMultipleQueries(queries); diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index aa1a32a08..eb5ae5741 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -191,8 +191,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query1.Category = DbCatConfig; query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("host_object_id", host); - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); if (groups) { ObjectLock olock(groups); @@ -211,8 +210,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group)); query2.WhereCriteria->Set("host_object_id", host); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } } @@ -226,8 +224,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query2.Category = DbCatConfig; query2.WhereCriteria = new Dictionary(); query2.WhereCriteria->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject())); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); /* parents */ for (const Checkable::Ptr& checkable : host->GetParents()) { @@ -250,8 +247,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query1.Type = DbQueryInsert; query1.Category = DbCatConfig; query1.Fields = fields1; - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); } DbObject::OnMultipleQueries(queries); @@ -268,8 +264,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query3.Category = DbCatConfig; query3.WhereCriteria = new Dictionary(); query3.WhereCriteria->Set("dependent_host_object_id", host); - - queries.push_back(query3); + queries.emplace_back(std::move(query3)); for (const Dependency::Ptr& dep : host->GetDependencies()) { Checkable::Ptr parent = dep->GetParent(); @@ -299,8 +294,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query2.Type = DbQueryInsert; query2.Category = DbCatConfig; query2.Fields = fields2; - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } DbObject::OnMultipleQueries(queries); @@ -316,8 +310,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query4.Category = DbCatConfig; query4.WhereCriteria = new Dictionary(); query4.WhereCriteria->Set("host_id", DbValue::FromObjectInsertID(host)); - - queries.push_back(query4); + queries.emplace_back(std::move(query4)); for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(host)) { Log(LogDebug, "HostDbObject") @@ -333,8 +326,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query_contact.Type = DbQueryInsert; query_contact.Category = DbCatConfig; query_contact.Fields = fields_contact; - - queries.push_back(query_contact); + queries.emplace_back(std::move(query_contact)); } DbObject::OnMultipleQueries(queries); @@ -350,8 +342,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query5.Category = DbCatConfig; query5.WhereCriteria = new Dictionary(); query5.WhereCriteria->Set("host_id", DbValue::FromObjectInsertID(host)); - - queries.push_back(query5); + queries.emplace_back(std::move(query5)); for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(host)) { Log(LogDebug, "HostDbObject") @@ -367,8 +358,7 @@ void HostDbObject::OnConfigUpdateHeavy(void) query_contact.Type = DbQueryInsert; query_contact.Category = DbCatConfig; query_contact.Fields = fields_contact; - - queries.push_back(query_contact); + queries.emplace_back(std::move(query_contact)); } DbObject::OnMultipleQueries(queries); diff --git a/lib/db_ido/idochecktask.cpp b/lib/db_ido/idochecktask.cpp index 707b1ed37..b3c11eefd 100644 --- a/lib/db_ido/idochecktask.cpp +++ b/lib/db_ido/idochecktask.cpp @@ -46,10 +46,10 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); String idoType = MacroProcessor::ResolveMacros("$ido_type$", resolvers, checkable->GetLastCheckResult(), NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 378d3f457..0086dc9ec 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -185,8 +185,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query1.Category = DbCatConfig; query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("service_object_id", service); - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); if (groups) { ObjectLock olock(groups); @@ -205,8 +204,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group)); query2.WhereCriteria->Set("service_object_id", service); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } } @@ -224,8 +222,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query2.Category = DbCatConfig; query2.WhereCriteria = new Dictionary(); query2.WhereCriteria->Set("dependent_service_object_id", service); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); for (const Dependency::Ptr& dep : service->GetDependencies()) { Checkable::Ptr parent = dep->GetParent(); @@ -258,8 +255,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query1.Type = DbQueryInsert; query1.Category = DbCatConfig; query1.Fields = fields1; - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); } DbObject::OnMultipleQueries(queries); @@ -276,8 +272,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query3.Category = DbCatConfig; query3.WhereCriteria = new Dictionary(); query3.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service)); - - queries.push_back(query3); + queries.emplace_back(std::move(query3)); for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) { Log(LogDebug, "ServiceDbObject") @@ -293,8 +288,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query_contact.Type = DbQueryInsert; query_contact.Category = DbCatConfig; query_contact.Fields = fields_contact; - - queries.push_back(query_contact); + queries.emplace_back(std::move(query_contact)); } DbObject::OnMultipleQueries(queries); @@ -310,8 +304,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query4.Category = DbCatConfig; query4.WhereCriteria = new Dictionary(); query4.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service)); - - queries.push_back(query4); + queries.emplace_back(std::move(query4)); for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) { Log(LogDebug, "ServiceDbObject") @@ -327,8 +320,7 @@ void ServiceDbObject::OnConfigUpdateHeavy(void) query_contact.Type = DbQueryInsert; query_contact.Category = DbCatConfig; query_contact.Fields = fields_contact; - - queries.push_back(query_contact); + queries.emplace_back(std::move(query_contact)); } DbObject::OnMultipleQueries(queries); diff --git a/lib/db_ido/userdbobject.cpp b/lib/db_ido/userdbobject.cpp index 9e25b8be4..fae23d925 100644 --- a/lib/db_ido/userdbobject.cpp +++ b/lib/db_ido/userdbobject.cpp @@ -94,8 +94,7 @@ void UserDbObject::OnConfigUpdateHeavy(void) query1.Category = DbCatConfig; query1.WhereCriteria = new Dictionary(); query1.WhereCriteria->Set("contact_object_id", user); - - queries.push_back(query1); + queries.emplace_back(std::move(query1)); if (groups) { ObjectLock olock(groups); @@ -114,8 +113,7 @@ void UserDbObject::OnConfigUpdateHeavy(void) query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */ query2.WhereCriteria->Set("contactgroup_id", DbValue::FromObjectInsertID(group)); query2.WhereCriteria->Set("contact_object_id", user); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); } } @@ -129,8 +127,7 @@ void UserDbObject::OnConfigUpdateHeavy(void) query2.Category = DbCatConfig; query2.WhereCriteria = new Dictionary(); query2.WhereCriteria->Set("contact_id", DbValue::FromObjectInsertID(user)); - - queries.push_back(query2); + queries.emplace_back(std::move(query2)); Dictionary::Ptr vars = user->GetVars(); @@ -155,8 +152,7 @@ void UserDbObject::OnConfigUpdateHeavy(void) query.Table = "contact_addresses"; query.Category = DbCatConfig; query.Fields = fields; - - queries.push_back(query); + queries.emplace_back(std::move(query)); } } diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index bc737b166..1ed3a8c97 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -420,7 +420,7 @@ void IdoMysqlConnection::Reconnect(void) SetObjectActive(dbobj, active); if (active) - activeDbObjs.push_back(dbobj); + activeDbObjs.emplace_back(std::move(dbobj)); } SetIDCacheValid(true); @@ -489,7 +489,7 @@ void IdoMysqlConnection::AsyncQuery(const String& query, const std::function 25000) { FinishAsyncQueries(); diff --git a/lib/icinga/checkcommand.cpp b/lib/icinga/checkcommand.cpp index e300515b9..167701a2e 100644 --- a/lib/icinga/checkcommand.cpp +++ b/lib/icinga/checkcommand.cpp @@ -28,10 +28,10 @@ REGISTER_TYPE(CheckCommand); void CheckCommand::Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { - std::vector arguments; - arguments.push_back(checkable); - arguments.push_back(cr); - arguments.push_back(resolvedMacros); - arguments.push_back(useResolvedMacros); - GetExecute()->Invoke(arguments); + GetExecute()->Invoke({ + checkable, + cr, + resolvedMacros, + useResolvedMacros + }); } diff --git a/lib/icinga/eventcommand.cpp b/lib/icinga/eventcommand.cpp index 54d54851c..886c89203 100644 --- a/lib/icinga/eventcommand.cpp +++ b/lib/icinga/eventcommand.cpp @@ -27,9 +27,9 @@ REGISTER_TYPE(EventCommand); void EventCommand::Execute(const Checkable::Ptr& checkable, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { - std::vector arguments; - arguments.push_back(checkable); - arguments.push_back(resolvedMacros); - arguments.push_back(useResolvedMacros); - GetExecute()->Invoke(arguments); + GetExecute()->Invoke({ + checkable, + resolvedMacros, + useResolvedMacros + }); } diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index c97bd1b67..465667ed4 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -222,8 +222,7 @@ Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const Resolver _1, std::cref(resolvers), cr, resolvedMacros, useResolvedMacros, recursionLevel + 1))); - std::vector args; - return func->Invoke(resolvers_this, args); + return func->InvokeThis(resolvers_this); } Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverList& resolvers, @@ -542,7 +541,7 @@ Value MacroProcessor::ResolveArguments(const Value& command, const Dictionary::P continue; } - args.push_back(arg); + args.emplace_back(std::move(arg)); } std::sort(args.begin(), args.end()); diff --git a/lib/icinga/notificationcommand.cpp b/lib/icinga/notificationcommand.cpp index fc99872f8..3313b76af 100644 --- a/lib/icinga/notificationcommand.cpp +++ b/lib/icinga/notificationcommand.cpp @@ -29,14 +29,14 @@ Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notificati const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros) { - std::vector arguments; - arguments.push_back(notification); - arguments.push_back(user); - arguments.push_back(cr); - arguments.push_back(type); - arguments.push_back(author); - arguments.push_back(comment); - arguments.push_back(resolvedMacros); - arguments.push_back(useResolvedMacros); - return GetExecute()->Invoke(arguments); + return GetExecute()->Invoke({ + notification, + user, + cr, + type, + author, + comment, + resolvedMacros, + useResolvedMacros, + }); } diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index f0b8b6644..ffb7fe864 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -244,12 +244,7 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting) return; } - std::vector arguments; - arguments.push_back(this); - arguments.push_back(begin); - arguments.push_back(end); - - Array::Ptr segments = GetUpdate()->Invoke(arguments); + Array::Ptr segments = GetUpdate()->Invoke({ this, begin, end }); { ObjectLock olock(this); diff --git a/lib/livestatus/hoststable.cpp b/lib/livestatus/hoststable.cpp index ce4cb2a83..e98a1aa25 100644 --- a/lib/livestatus/hoststable.cpp +++ b/lib/livestatus/hoststable.cpp @@ -323,9 +323,10 @@ Value HostsTable::NotesExpandedAccessor(const Value& row) if (!host) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "host", host }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(host->GetNotes(), resolvers, CheckResult::Ptr()); } @@ -347,9 +348,10 @@ Value HostsTable::NotesUrlExpandedAccessor(const Value& row) if (!host) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "host", host }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(host->GetNotesUrl(), resolvers); } @@ -371,9 +373,10 @@ Value HostsTable::ActionUrlExpandedAccessor(const Value& row) if (!host) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "host", host }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(host->GetActionUrl(), resolvers); } @@ -427,9 +430,10 @@ Value HostsTable::IconImageExpandedAccessor(const Value& row) if (!host) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "host", host }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(host->GetIconImage(), resolvers); } diff --git a/lib/livestatus/livestatusquery.cpp b/lib/livestatus/livestatusquery.cpp index 3132fe532..6dbb52c9a 100644 --- a/lib/livestatus/livestatusquery.cpp +++ b/lib/livestatus/livestatusquery.cpp @@ -309,12 +309,12 @@ Filter::Ptr LivestatusQuery::ParseFilter(const String& params, unsigned long& fr break; } - tokens.push_back(temp_buffer.SubStr(0, sp_index)); + tokens.emplace_back(temp_buffer.SubStr(0, sp_index)); temp_buffer = temp_buffer.SubStr(sp_index + 1); } /* add the rest as value */ - tokens.push_back(temp_buffer); + tokens.emplace_back(std::move(temp_buffer)); if (tokens.size() == 2) tokens.push_back(""); @@ -490,7 +490,7 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream) column_objs.reserve(columns.size()); for (const String& columnName : columns) - column_objs.push_back(std::make_pair(columnName, table->GetColumn(columnName))); + column_objs.emplace_back(columnName, table->GetColumn(columnName)); for (const LivestatusRowValue& object : objects) { Array::Ptr row = new Array(); @@ -520,7 +520,7 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream) for (const String& columnName : m_Columns) { Column column = table->GetColumn(columnName); - statsKey.push_back(column.ExtractValue(object.Row, object.GroupByType, object.GroupByObject)); + statsKey.emplace_back(column.ExtractValue(object.Row, object.GroupByType, object.GroupByObject)); } auto it = allStats.find(statsKey); diff --git a/lib/livestatus/servicestable.cpp b/lib/livestatus/servicestable.cpp index d7583da2c..76baa3bca 100644 --- a/lib/livestatus/servicestable.cpp +++ b/lib/livestatus/servicestable.cpp @@ -375,10 +375,11 @@ Value ServicesTable::NotesExpandedAccessor(const Value& row) if (!service) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", service->GetHost())); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "service", service }, + { "host", service->GetHost() }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(service->GetNotes(), resolvers); } @@ -400,10 +401,11 @@ Value ServicesTable::NotesUrlExpandedAccessor(const Value& row) if (!service) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", service->GetHost())); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "service", service }, + { "host", service->GetHost() }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(service->GetNotesUrl(), resolvers); } @@ -425,10 +427,11 @@ Value ServicesTable::ActionUrlExpandedAccessor(const Value& row) if (!service) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", service->GetHost())); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "service", service }, + { "host", service->GetHost() }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(service->GetActionUrl(), resolvers); } @@ -450,10 +453,11 @@ Value ServicesTable::IconImageExpandedAccessor(const Value& row) if (!service) return Empty; - MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", service->GetHost())); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + MacroProcessor::ResolverList resolvers { + { "service", service }, + { "host", service->GetHost() }, + { "icinga", IcingaApplication::GetInstance() } + }; return MacroProcessor::ResolveMacros(service->GetIconImage(), resolvers); } diff --git a/lib/livestatus/table.cpp b/lib/livestatus/table.cpp index 34659f18c..1e121ecb1 100644 --- a/lib/livestatus/table.cpp +++ b/lib/livestatus/table.cpp @@ -144,8 +144,7 @@ bool Table::FilteredAddRow(std::vector& rs, const Filter::Pt rval.GroupByType = groupByType; rval.GroupByObject = groupByObject; - rs.push_back(rval); - + rs.emplace_back(std::move(rval)); } return true; diff --git a/lib/methods/clrchecktask.cpp b/lib/methods/clrchecktask.cpp index 576538524..20640898b 100644 --- a/lib/methods/clrchecktask.cpp +++ b/lib/methods/clrchecktask.cpp @@ -156,10 +156,10 @@ void ClrCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); Dictionary::Ptr envMacros = new Dictionary(); diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index 919e7fbed..80208b66d 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -52,10 +52,10 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(), NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/methods/dummychecktask.cpp b/lib/methods/dummychecktask.cpp index 7f6b89a7c..652ef7e4a 100644 --- a/lib/methods/dummychecktask.cpp +++ b/lib/methods/dummychecktask.cpp @@ -44,10 +44,10 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(), NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index d2953b0dd..4507bd10a 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -46,10 +46,10 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), resolvers, resolvedMacros, useResolvedMacros, diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index 51308f555..594451896 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -44,10 +44,10 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable, MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); PluginUtility::ExecuteCommand(commandObj, checkable, checkable->GetLastCheckResult(), resolvers, resolvedMacros, useResolvedMacros, diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index 3485c5c0f..b4ec80df2 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -55,14 +55,14 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, tie(host, service) = GetHostService(checkable); MacroProcessor::ResolverList resolvers; - resolvers.push_back(std::make_pair("user", user)); - resolvers.push_back(std::make_pair("notification", notificationExtra)); - resolvers.push_back(std::make_pair("notification", notification)); + resolvers.emplace_back("user", user); + resolvers.emplace_back("notification", notificationExtra); + resolvers.emplace_back("notification", notification); if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("command", commandObj)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("command", commandObj); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers, resolvedMacros, useResolvedMacros, diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index ce648cd54..f113aef13 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -363,7 +363,7 @@ void ElasticsearchWriter::Enqueue(String type, const Dictionary::Ptr& fields, do Log(LogDebug, "ElasticsearchWriter") << "Add to fields to message list: '" << fieldsBody << "'."; - m_DataBuffer.push_back(indexBody + fieldsBody); + m_DataBuffer.emplace_back(indexBody + fieldsBody); /* Flush if we've buffered too much to prevent excessive memory use. */ if (static_cast(m_DataBuffer.size()) >= GetFlushThreshold()) { @@ -412,10 +412,10 @@ void ElasticsearchWriter::SendRequest(const String& body) /* Specify the index path. Best practice is a daily rotation. * Example: http://localhost:9200/icinga2-2017.09.11?pretty=1 */ - path.push_back(GetIndex() + "-" + Utility::FormatDateTime("%Y.%m.%d", Utility::GetTime())); + path.emplace_back(GetIndex() + "-" + Utility::FormatDateTime("%Y.%m.%d", Utility::GetTime())); /* Use the bulk message format. */ - path.push_back("_bulk"); + path.emplace_back("_bulk"); url->SetPath(path); diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 86611393c..b87104358 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -199,9 +199,9 @@ void GraphiteWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); String prefix; diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index dc8e48955..e9636645c 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -194,9 +194,9 @@ void InfluxdbWriter::InternalCheckResultHandler(const Checkable::Ptr& checkable, MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); String prefix; diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 3200252ff..cb2da1150 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -100,9 +100,9 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C MacroProcessor::ResolverList resolvers; if (service) - resolvers.push_back(std::make_pair("service", service)); - resolvers.push_back(std::make_pair("host", host)); - resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); + resolvers.emplace_back("service", service); + resolvers.emplace_back("host", host); + resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); if (service) { String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, NULL, &PerfdataWriter::EscapeMacroMetric); diff --git a/lib/remote/apiclient.cpp b/lib/remote/apiclient.cpp index b4cc25813..8e91669f5 100644 --- a/lib/remote/apiclient.cpp +++ b/lib/remote/apiclient.cpp @@ -87,7 +87,7 @@ void ApiClient::TypesHttpCompletionCallback(HttpRequest& request, HttpResponse& type->Name = typeInfo->Get("name"); type->PluralName = typeInfo->Get("plural_name"); // TODO: attributes - types.push_back(type); + types.emplace_back(std::move(type)); } callback(boost::exception_ptr(), types); @@ -204,7 +204,7 @@ void ApiClient::ObjectsHttpCompletionCallback(HttpRequest& request, ApiObjectReference ref; ref.Name = refInfo->Get("name"); ref.Type = refInfo->Get("type"); - object->UsedBy.push_back(ref); + object->UsedBy.emplace_back(std::move(ref)); } } diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 4c3d4d06e..6e964c921 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -758,7 +758,7 @@ void ApiListener::ApiReconnectTimerHandler(void) std::vector names; for (const Endpoint::Ptr& endpoint : ConfigType::GetObjectsByType()) if (endpoint->GetConnected()) - names.push_back(endpoint->GetName() + " (" + Convert::ToString(endpoint->GetClients().size()) + ")"); + names.emplace_back(endpoint->GetName() + " (" + Convert::ToString(endpoint->GetClients().size()) + ")"); Log(LogNotice, "ApiListener") << "Connected endpoints: " << Utility::NaturalJoin(names); diff --git a/lib/remote/configpackageutility.cpp b/lib/remote/configpackageutility.cpp index 61cf09139..4bcff3504 100644 --- a/lib/remote/configpackageutility.cpp +++ b/lib/remote/configpackageutility.cpp @@ -66,8 +66,7 @@ std::vector ConfigPackageUtility::GetPackages(void) void ConfigPackageUtility::CollectDirNames(const String& path, std::vector& dirs) { - String name = Utility::BaseName(path); - dirs.push_back(name); + dirs.emplace_back(Utility::BaseName(path)); } bool ConfigPackageUtility::PackageExists(const String& name) @@ -279,7 +278,7 @@ void ConfigPackageUtility::CollectPaths(const String& path, std::vector FilterUtility::GetFilterTargets(const QueryDescription& qd, c if (!FilterUtility::EvaluateFilter(permissionFrame, permissionFilter, target, variableName)) BOOST_THROW_EXCEPTION(ScriptError("Access denied to object '" + name + "' of type '" + type + "'")); - result.push_back(target); + result.emplace_back(std::move(target)); } attr = provider->GetPluralName(type); @@ -228,7 +228,7 @@ std::vector FilterUtility::GetFilterTargets(const QueryDescription& qd, c if (!FilterUtility::EvaluateFilter(permissionFrame, permissionFilter, target, variableName)) BOOST_THROW_EXCEPTION(ScriptError("Access denied to object '" + name + "' of type '" + type + "'")); - result.push_back(target); + result.emplace_back(std::move(target)); } } } diff --git a/lib/remote/httpclientconnection.cpp b/lib/remote/httpclientconnection.cpp index e730ff2fa..8cb6bbfdd 100644 --- a/lib/remote/httpclientconnection.cpp +++ b/lib/remote/httpclientconnection.cpp @@ -169,7 +169,7 @@ std::shared_ptr HttpClientConnection::NewRequest(void) void HttpClientConnection::SubmitRequest(const std::shared_ptr& request, const HttpCompletionCallback& callback) { - m_Requests.push_back(std::make_pair(request, callback)); + m_Requests.emplace_back(request, callback); request->Finish(); } diff --git a/lib/remote/httphandler.cpp b/lib/remote/httphandler.cpp index 1273fe754..f0dd17426 100644 --- a/lib/remote/httphandler.cpp +++ b/lib/remote/httphandler.cpp @@ -72,7 +72,7 @@ void HttpHandler::ProcessRequest(const ApiUser::Ptr& user, HttpRequest& request, if (current_handlers) { ObjectLock olock(current_handlers); - for (const HttpHandler::Ptr current_handler : current_handlers) { + for (const HttpHandler::Ptr& current_handler : current_handlers) { handlers.push_back(current_handler); } } diff --git a/lib/remote/httpresponse.cpp b/lib/remote/httpresponse.cpp index 587b58747..5499d6d32 100644 --- a/lib/remote/httpresponse.cpp +++ b/lib/remote/httpresponse.cpp @@ -57,7 +57,7 @@ void HttpResponse::SetStatus(int code, const String& message) void HttpResponse::AddHeader(const String& key, const String& value) { - m_Headers.push_back(key + ": " + value + "\r\n"); + m_Headers.emplace_back(key + ": " + value + "\r\n"); } void HttpResponse::FinishHeaders(void) diff --git a/lib/remote/infohandler.cpp b/lib/remote/infohandler.cpp index ce8a6a1a3..89de1341a 100644 --- a/lib/remote/infohandler.cpp +++ b/lib/remote/infohandler.cpp @@ -62,7 +62,7 @@ bool InfoHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request, if (hasFilter) name += " (filtered)"; - permInfo.push_back(name); + permInfo.emplace_back(std::move(name)); } } diff --git a/lib/remote/url.cpp b/lib/remote/url.cpp index 16a0dbd88..2fe56d730 100644 --- a/lib/remote/url.cpp +++ b/lib/remote/url.cpp @@ -212,8 +212,7 @@ void Url::AddQueryElement(const String& name, const String& value) { auto it = m_Query.find(name); if (it == m_Query.end()) { - m_Query[name] = std::vector(); - m_Query[name].push_back(value); + m_Query[name] = std::vector { value }; } else m_Query[name].push_back(value); } @@ -363,9 +362,7 @@ bool Url::ParsePath(const String& path) if (!ValidateToken(token, ACPATHSEGMENT)) return false; - String decodedToken = Utility::UnescapeString(token); - - m_Path.push_back(decodedToken); + m_Path.emplace_back(Utility::UnescapeString(token)); } return true; @@ -411,11 +408,9 @@ bool Url::ParseQuery(const String& query) auto it = m_Query.find(key); if (it == m_Query.end()) { - m_Query[key] = std::vector(); - m_Query[key].push_back(value); + m_Query[key] = std::vector { std::move(value) }; } else - m_Query[key].push_back(value); - + m_Query[key].emplace_back(std::move(value)); } return true;