Skip to content

Commit 30e176f

Browse files
committed
Fix Tier 2 code review findings
1 parent a94dd67 commit 30e176f

4 files changed

Lines changed: 230 additions & 211 deletions

File tree

plugin_arch/EventBus.hpp

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ class EventBus {
167167

168168
const auto& topic = topic_it->second;
169169

170-
if (erase_by_id(subscriptions_, topic, id) ||
171-
erase_typed_by_id(typed_subscriptions_, topic, id) ||
172-
erase_vetoable_by_id(vetoable_subscriptions_, topic, id)) {
170+
if (erase_subscription_by_id(subscriptions_, topic, id) ||
171+
erase_subscription_by_id(typed_subscriptions_, topic, id) ||
172+
erase_subscription_by_id(vetoable_subscriptions_, topic, id)) {
173173
id_to_topic_.erase(topic_it);
174174
return true;
175175
}
@@ -256,34 +256,10 @@ class EventBus {
256256
});
257257
}
258258

259-
// Erase helpers for unsubscribe — search each map type.
260-
static bool erase_by_id(
261-
std::unordered_map<std::string, std::vector<Subscription>>& map,
262-
const std::string& topic, SubscriptionId id) {
263-
auto it = map.find(topic);
264-
if (it == map.end()) return false;
265-
auto& subs = it->second;
266-
for (auto sit = subs.begin(); sit != subs.end(); ++sit) {
267-
if (sit->id == id) { subs.erase(sit); return true; }
268-
}
269-
return false;
270-
}
271-
272-
static bool erase_typed_by_id(
273-
std::unordered_map<std::string, std::vector<TypedSubscription>>& map,
274-
const std::string& topic, SubscriptionId id) {
275-
auto it = map.find(topic);
276-
if (it == map.end()) return false;
277-
auto& subs = it->second;
278-
for (auto sit = subs.begin(); sit != subs.end(); ++sit) {
279-
if (sit->id == id) { subs.erase(sit); return true; }
280-
}
281-
return false;
282-
}
283-
284-
static bool erase_vetoable_by_id(
285-
std::unordered_map<std::string, std::vector<VetoableSubscription>>& map,
286-
const std::string& topic, SubscriptionId id) {
259+
// Erase a subscription by ID from a topic→subscriptions map.
260+
template <typename Map>
261+
static bool erase_subscription_by_id(Map& map, const std::string& topic,
262+
SubscriptionId id) {
287263
auto it = map.find(topic);
288264
if (it == map.end()) return false;
289265
auto& subs = it->second;

0 commit comments

Comments
 (0)