mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
Merge pull request #9641 from Icinga/code-optimization-1
Some trivial code optimisations
This commit is contained in:
commit
27af8829f2
@ -15,21 +15,24 @@ boost::thread_specific_ptr<Loader::DeferredInitializerPriorityQueue>& Loader::Ge
|
||||
|
||||
void Loader::ExecuteDeferredInitializers()
|
||||
{
|
||||
if (!GetDeferredInitializers().get())
|
||||
auto& initializers = GetDeferredInitializers();
|
||||
if (!initializers.get())
|
||||
return;
|
||||
|
||||
while (!GetDeferredInitializers().get()->empty()) {
|
||||
DeferredInitializer initializer = GetDeferredInitializers().get()->top();
|
||||
GetDeferredInitializers().get()->pop();
|
||||
while (!initializers->empty()) {
|
||||
DeferredInitializer initializer = initializers->top();
|
||||
initializers->pop();
|
||||
initializer();
|
||||
}
|
||||
}
|
||||
|
||||
void Loader::AddDeferredInitializer(const std::function<void()>& callback, InitializePriority priority)
|
||||
{
|
||||
if (!GetDeferredInitializers().get())
|
||||
GetDeferredInitializers().reset(new Loader::DeferredInitializerPriorityQueue());
|
||||
auto& initializers = GetDeferredInitializers();
|
||||
if (!initializers.get()) {
|
||||
initializers.reset(new Loader::DeferredInitializerPriorityQueue());
|
||||
}
|
||||
|
||||
GetDeferredInitializers().get()->push(DeferredInitializer(callback, priority));
|
||||
initializers->push(DeferredInitializer(callback, priority));
|
||||
}
|
||||
|
||||
|
@ -211,18 +211,18 @@ Value icinga::operator+(const Value& lhs, const Value& rhs)
|
||||
return static_cast<double>(lhs) + static_cast<double>(rhs);
|
||||
if ((lhs.IsString() || lhs.IsEmpty() || lhs.IsNumber()) && (rhs.IsString() || rhs.IsEmpty() || rhs.IsNumber()) && (!(lhs.IsEmpty() && rhs.IsEmpty()) || lhs.IsString() || rhs.IsString()))
|
||||
return static_cast<String>(lhs) + static_cast<String>(rhs);
|
||||
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return static_cast<double>(lhs) + static_cast<double>(rhs);
|
||||
else if (lhs.IsObjectType<DateTime>() && rhs.IsNumber())
|
||||
return new DateTime(Convert::ToDateTimeValue(lhs) + rhs);
|
||||
else if ((lhs.IsObjectType<Array>() || lhs.IsEmpty()) && (rhs.IsObjectType<Array>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) {
|
||||
else if ((lhs.IsObjectType<Array>() || lhs.IsEmpty()) && (rhs.IsObjectType<Array>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) {
|
||||
Array::Ptr result = new Array();
|
||||
if (!lhs.IsEmpty())
|
||||
static_cast<Array::Ptr>(lhs)->CopyTo(result);
|
||||
if (!rhs.IsEmpty())
|
||||
static_cast<Array::Ptr>(rhs)->CopyTo(result);
|
||||
return result;
|
||||
} else if ((lhs.IsObjectType<Dictionary>() || lhs.IsEmpty()) && (rhs.IsObjectType<Dictionary>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) {
|
||||
} else if ((lhs.IsObjectType<Dictionary>() || lhs.IsEmpty()) && (rhs.IsObjectType<Dictionary>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) {
|
||||
Dictionary::Ptr result = new Dictionary();
|
||||
if (!lhs.IsEmpty())
|
||||
static_cast<Dictionary::Ptr>(lhs)->CopyTo(result);
|
||||
@ -262,7 +262,7 @@ Value icinga::operator-(const Value& lhs, const Value& rhs)
|
||||
return new DateTime(Convert::ToDateTimeValue(lhs) - rhs);
|
||||
else if (lhs.IsObjectType<DateTime>() && rhs.IsObjectType<DateTime>())
|
||||
return Convert::ToDateTimeValue(lhs) - Convert::ToDateTimeValue(rhs);
|
||||
else if ((lhs.IsObjectType<DateTime>() || lhs.IsEmpty()) && (rhs.IsObjectType<DateTime>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
else if ((lhs.IsObjectType<DateTime>() || lhs.IsEmpty()) && (rhs.IsObjectType<DateTime>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return new DateTime(Convert::ToDateTimeValue(lhs) - Convert::ToDateTimeValue(rhs));
|
||||
else if ((lhs.IsObjectType<Array>() || lhs.IsEmpty()) && (rhs.IsObjectType<Array>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty())) {
|
||||
if (lhs.IsEmpty())
|
||||
@ -554,7 +554,7 @@ bool icinga::operator<(const Value& lhs, const Value& rhs)
|
||||
return static_cast<String>(lhs) < static_cast<String>(rhs);
|
||||
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return static_cast<double>(lhs) < static_cast<double>(rhs);
|
||||
else if ((lhs.IsObjectType<DateTime>() || lhs.IsEmpty()) && (rhs.IsObjectType<DateTime>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
else if ((lhs.IsObjectType<DateTime>() || lhs.IsEmpty()) && (rhs.IsObjectType<DateTime>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return Convert::ToDateTimeValue(lhs) < Convert::ToDateTimeValue(rhs);
|
||||
else if (lhs.IsObjectType<Array>() && rhs.IsObjectType<Array>()) {
|
||||
Array::Ptr larr = lhs;
|
||||
@ -607,7 +607,7 @@ bool icinga::operator>(const Value& lhs, const Value& rhs)
|
||||
return static_cast<String>(lhs) > static_cast<String>(rhs);
|
||||
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return static_cast<double>(lhs) > static_cast<double>(rhs);
|
||||
else if ((lhs.IsObjectType<DateTime>() || lhs.IsEmpty()) && (rhs.IsObjectType<DateTime>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
else if ((lhs.IsObjectType<DateTime>() || lhs.IsEmpty()) && (rhs.IsObjectType<DateTime>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return Convert::ToDateTimeValue(lhs) > Convert::ToDateTimeValue(rhs);
|
||||
else if (lhs.IsObjectType<Array>() && rhs.IsObjectType<Array>()) {
|
||||
Array::Ptr larr = lhs;
|
||||
@ -660,7 +660,7 @@ bool icinga::operator<=(const Value& lhs, const Value& rhs)
|
||||
return static_cast<String>(lhs) <= static_cast<String>(rhs);
|
||||
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return static_cast<double>(lhs) <= static_cast<double>(rhs);
|
||||
else if ((lhs.IsObjectType<DateTime>() || lhs.IsEmpty()) && (rhs.IsObjectType<DateTime>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
else if ((lhs.IsObjectType<DateTime>() || lhs.IsEmpty()) && (rhs.IsObjectType<DateTime>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return Convert::ToDateTimeValue(lhs) <= Convert::ToDateTimeValue(rhs);
|
||||
else
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Operator <= cannot be applied to values of type '" + lhs.GetTypeName() + "' and '" + rhs.GetTypeName() + "'"));
|
||||
@ -692,7 +692,7 @@ bool icinga::operator>=(const Value& lhs, const Value& rhs)
|
||||
return static_cast<String>(lhs) >= static_cast<String>(rhs);
|
||||
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return static_cast<double>(lhs) >= static_cast<double>(rhs);
|
||||
else if ((lhs.IsObjectType<DateTime>() || lhs.IsEmpty()) && (rhs.IsObjectType<DateTime>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
else if ((lhs.IsObjectType<DateTime>() || lhs.IsEmpty()) && (rhs.IsObjectType<DateTime>() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return Convert::ToDateTimeValue(lhs) >= Convert::ToDateTimeValue(rhs);
|
||||
else
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Operator >= cannot be applied to values of type '" + lhs.GetTypeName() + "' and '" + rhs.GetTypeName() + "'"));
|
||||
|
@ -148,7 +148,7 @@ public:
|
||||
{
|
||||
ConfigItem::Ptr item = ConfigItem::GetByTypeAndName(Type::GetByName(type), name);
|
||||
|
||||
if (!item || (item && item->IsAbstract()))
|
||||
if (!item || item->IsAbstract())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
|
||||
static thread_local CheckCommand::Ptr ExecuteOverride;
|
||||
|
||||
virtual void Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
||||
void Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
||||
const Dictionary::Ptr& resolvedMacros = nullptr,
|
||||
bool useResolvedMacros = false);
|
||||
};
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
|
||||
static thread_local EventCommand::Ptr ExecuteOverride;
|
||||
|
||||
virtual void Execute(const Checkable::Ptr& checkable,
|
||||
void Execute(const Checkable::Ptr& checkable,
|
||||
const Dictionary::Ptr& resolvedMacros = nullptr,
|
||||
bool useResolvedMacros = false);
|
||||
};
|
||||
|
@ -853,7 +853,7 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi
|
||||
Zone::Ptr myZone = Zone::GetLocalZone();
|
||||
auto parent (myZone->GetParent());
|
||||
|
||||
if (parent == eZone || !parent && eZone == myZone) {
|
||||
if (parent == eZone || (!parent && eZone == myZone)) {
|
||||
JsonRpcConnection::SendCertificateRequest(aclient, nullptr, String());
|
||||
|
||||
if (Utility::PathExists(ApiListener::GetCertificateRequestsDir())) {
|
||||
@ -1325,7 +1325,7 @@ void ApiListener::OpenLogFile()
|
||||
|
||||
Utility::MkDirP(Utility::DirName(path), 0750);
|
||||
|
||||
auto *fp = new std::fstream(path.CStr(), std::fstream::out | std::ofstream::app);
|
||||
std::unique_ptr<std::fstream> fp = std::make_unique<std::fstream>(path.CStr(), std::fstream::out | std::ofstream::app);
|
||||
|
||||
if (!fp->good()) {
|
||||
Log(LogWarning, "ApiListener")
|
||||
@ -1333,7 +1333,7 @@ void ApiListener::OpenLogFile()
|
||||
return;
|
||||
}
|
||||
|
||||
m_LogFile = new StdioStream(fp, true);
|
||||
m_LogFile = new StdioStream(fp.release(), true);
|
||||
m_LogMessageCount = 0;
|
||||
SetLogMessageTimestamp(Utility::GetTime());
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ void ConfigObjectUtility::RepairPackage(const String& package)
|
||||
|
||||
String foundActiveStage;
|
||||
|
||||
for (fs::recursive_directory_iterator it(path); it != end; it++) {
|
||||
for (fs::recursive_directory_iterator it(path); it != end; ++it) {
|
||||
boost::system::error_code ec;
|
||||
|
||||
const fs::path d = *it;
|
||||
|
Loading…
x
Reference in New Issue
Block a user