Optimize sensorsOwnerMatch init
`sensorsOwnerMatch` should init once, not every time a sensor is added.
Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
Change-Id: I3a610d73bd732e7a019a4f53b40eac7df4fb256b
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index 53d1b42..ffc1ee5 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -190,29 +190,29 @@
sensorCacheMap[s.first].reset();
}
}));
- sensorsOwnerMatch = std::make_unique<sdbusplus::bus::match_t>(
- bus, nameOwnerChanged(), [](auto& msg) {
- std::string name;
- std::string oldOwner;
- std::string newOwner;
- msg.read(name, oldOwner, newOwner);
-
- if (!name.empty() && newOwner.empty())
- {
- // The service exits
- const auto it = serviceToIdMap.find(name);
- if (it == serviceToIdMap.end())
- {
- return;
- }
- for (const auto& id : it->second)
- {
- // Invalidate cache
- sensorCacheMap[id].reset();
- }
- }
- });
}
+ sensorsOwnerMatch = std::make_unique<sdbusplus::bus::match_t>(
+ bus, nameOwnerChanged(), [](auto& msg) {
+ std::string name;
+ std::string oldOwner;
+ std::string newOwner;
+ msg.read(name, oldOwner, newOwner);
+
+ if (!name.empty() && newOwner.empty())
+ {
+ // The service exits
+ const auto it = serviceToIdMap.find(name);
+ if (it == serviceToIdMap.end())
+ {
+ return;
+ }
+ for (const auto& id : it->second)
+ {
+ // Invalidate cache
+ sensorCacheMap[id].reset();
+ }
+ }
+ });
}
#endif