Skip to content

Commit

Permalink
Use find instead of count/at
Browse files Browse the repository at this point in the history
  • Loading branch information
Molter73 committed Apr 2, 2024
1 parent 233b287 commit ea234c9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions collector/lib/ContainerMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ class ContainerMetadata {
}

inline std::string GetContainerLabel(const std::string& container_id, const std::string& label) {
const auto& containers = inspector_->m_container_manager.get_containers();
if (containers->count(container_id) == 0) {
const auto containers = inspector_->m_container_manager.get_containers();
const auto& container = containers->find(container_id);
if (container == containers->end()) {
return "";
}

const auto& container = containers->at(container_id);
if (container->m_labels.count(label) == 0) {
const auto& labels = container->second->m_labels;
const auto& label_it = labels.find(label);
if (label_it == labels.end()) {
return "";
}

return container->m_labels.at(label);
return label_it->second;
}

private:
Expand Down

0 comments on commit ea234c9

Please sign in to comment.