mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
Drop superfluous mutex lock & don't manually unpack std::tuple
This commit is contained in:
parent
693d094ebc
commit
864e2aaae0
@ -138,7 +138,6 @@ std::vector<Dependency::Ptr> DependencyGroup::GetDependenciesForChild(const Chec
|
|||||||
*/
|
*/
|
||||||
void DependencyGroup::LoadParents(std::set<Checkable::Ptr>& parents) const
|
void DependencyGroup::LoadParents(std::set<Checkable::Ptr>& parents) const
|
||||||
{
|
{
|
||||||
std::lock_guard lock(m_Mutex);
|
|
||||||
for (auto& [compositeKey, children] : m_Members) {
|
for (auto& [compositeKey, children] : m_Members) {
|
||||||
parents.insert(std::get<0>(compositeKey));
|
parents.insert(std::get<0>(compositeKey));
|
||||||
}
|
}
|
||||||
@ -203,7 +202,7 @@ void DependencyGroup::RemoveDependency(const Dependency::Ptr& dependency)
|
|||||||
/**
|
/**
|
||||||
* Copy the dependency objects of the current dependency group to the provided dependency group (destination).
|
* Copy the dependency objects of the current dependency group to the provided dependency group (destination).
|
||||||
*
|
*
|
||||||
* @param dest The dependency group to move the dependencies to.
|
* @param dest The dependency group to copy the dependencies to.
|
||||||
*/
|
*/
|
||||||
void DependencyGroup::CopyDependenciesTo(const DependencyGroup::Ptr& dest)
|
void DependencyGroup::CopyDependenciesTo(const DependencyGroup::Ptr& dest)
|
||||||
{
|
{
|
||||||
@ -274,24 +273,20 @@ String DependencyGroup::GetCompositeKey()
|
|||||||
// not achievable using pointers.
|
// not achievable using pointers.
|
||||||
using StringTuple = std::tuple<String, String, int, bool>;
|
using StringTuple = std::tuple<String, String, int, bool>;
|
||||||
std::vector<StringTuple> compositeKeys;
|
std::vector<StringTuple> compositeKeys;
|
||||||
{
|
|
||||||
std::lock_guard lock(m_Mutex);
|
|
||||||
for (auto& [compositeKey, _] : m_Members) {
|
for (auto& [compositeKey, _] : m_Members) {
|
||||||
auto [parent, tp, stateFilter, ignoreSoftStates] = compositeKey;
|
auto [parent, tp, stateFilter, ignoreSoftStates] = compositeKey;
|
||||||
compositeKeys.emplace_back(parent->GetName(), tp ? tp->GetName() : "", stateFilter, ignoreSoftStates);
|
compositeKeys.emplace_back(parent->GetName(), tp ? tp->GetName() : "", stateFilter, ignoreSoftStates);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// IMPORTANT: The order of the composite keys must be sorted to ensure the deterministic hash value.
|
// IMPORTANT: The order of the composite keys must be sorted to ensure the deterministic hash value.
|
||||||
std::sort(compositeKeys.begin(), compositeKeys.end());
|
std::sort(compositeKeys.begin(), compositeKeys.end());
|
||||||
|
|
||||||
Array::Ptr data(new Array{GetRedundancyGroupName()});
|
Array::Ptr data(new Array{GetRedundancyGroupName()});
|
||||||
for (auto& compositeKey : compositeKeys) {
|
for (auto& compositeKey : compositeKeys) {
|
||||||
auto [parent, tp, stateFilter, ignoreSoftStates] = compositeKey;
|
// std::apply is used to unpack the composite key tuple and add its elements to the data array.
|
||||||
data->Add(std::move(parent));
|
// It's like manually expanding the tuple into x variables and then adding them one by one to the array.
|
||||||
data->Add(std::move(tp));
|
// See https://en.cppreference.com/w/cpp/language/fold for more information.
|
||||||
data->Add(stateFilter);
|
std::apply([&data](auto&&... args) { (data->Add(std::move(args)), ...); }, std::move(compositeKey));
|
||||||
data->Add(ignoreSoftStates);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return PackObject(data);
|
return PackObject(data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user