Commit 7db8bdffed546006b50f63da5e67e2a89e008930
1 parent
a75812d3
Fiddle with recursion order for compiler TCO
Showing
2 changed files
with
11 additions
and
20 deletions
subscriptionstore.cpp
| @@ -57,30 +57,25 @@ void SubscriptionStore::removeClient(const Client_p &client) | @@ -57,30 +57,25 @@ void SubscriptionStore::removeClient(const Client_p &client) | ||
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | // TODO: should I implement cache, this needs to be changed to returning a list of clients. | 59 | // TODO: should I implement cache, this needs to be changed to returning a list of clients. |
| 60 | -bool SubscriptionStore::publishNonRecursively(const MqttPacket &packet, const std::forward_list<std::string> &subscribers) const | 60 | +void SubscriptionStore::publishNonRecursively(const MqttPacket &packet, const std::forward_list<std::string> &subscribers) const |
| 61 | { | 61 | { |
| 62 | - bool result = false; | ||
| 63 | - | ||
| 64 | for (const std::string &client_id : subscribers) | 62 | for (const std::string &client_id : subscribers) |
| 65 | { | 63 | { |
| 66 | auto client_it = clients_by_id_const.find(client_id); | 64 | auto client_it = clients_by_id_const.find(client_id); |
| 67 | if (client_it != clients_by_id_const.end()) | 65 | if (client_it != clients_by_id_const.end()) |
| 68 | { | 66 | { |
| 69 | client_it->second->writeMqttPacketAndBlameThisClient(packet); | 67 | client_it->second->writeMqttPacketAndBlameThisClient(packet); |
| 70 | - result = true; | ||
| 71 | } | 68 | } |
| 72 | } | 69 | } |
| 73 | - | ||
| 74 | - return result; | ||
| 75 | } | 70 | } |
| 76 | 71 | ||
| 77 | -bool SubscriptionStore::publishRecursively(std::list<std::string>::const_iterator cur_subtopic_it, std::list<std::string>::const_iterator end, | 72 | +void SubscriptionStore::publishRecursively(std::list<std::string>::const_iterator cur_subtopic_it, std::list<std::string>::const_iterator end, |
| 78 | std::unique_ptr<SubscriptionNode> &this_node, const MqttPacket &packet) const | 73 | std::unique_ptr<SubscriptionNode> &this_node, const MqttPacket &packet) const |
| 79 | { | 74 | { |
| 80 | if (cur_subtopic_it == end) // This is the end of the topic path, so look for subscribers here. | 75 | if (cur_subtopic_it == end) // This is the end of the topic path, so look for subscribers here. |
| 81 | { | 76 | { |
| 82 | publishNonRecursively(packet, this_node->subscribers); | 77 | publishNonRecursively(packet, this_node->subscribers); |
| 83 | - return true; | 78 | + return; |
| 84 | } | 79 | } |
| 85 | 80 | ||
| 86 | std::string cur_subtop = *cur_subtopic_it; | 81 | std::string cur_subtop = *cur_subtopic_it; |
| @@ -88,26 +83,22 @@ bool SubscriptionStore::publishRecursively(std::list<std::string>::const_iterato | @@ -88,26 +83,22 @@ bool SubscriptionStore::publishRecursively(std::list<std::string>::const_iterato | ||
| 88 | 83 | ||
| 89 | const auto next_subtopic = ++cur_subtopic_it; | 84 | const auto next_subtopic = ++cur_subtopic_it; |
| 90 | 85 | ||
| 86 | + const auto pound_sign_node = this_node->children.find("#"); | ||
| 87 | + if (pound_sign_node != this_node->children.end()) | ||
| 88 | + { | ||
| 89 | + publishNonRecursively(packet, pound_sign_node->second->subscribers); | ||
| 90 | + } | ||
| 91 | + | ||
| 91 | if (sub_node != this_node->children.end()) | 92 | if (sub_node != this_node->children.end()) |
| 92 | { | 93 | { |
| 93 | publishRecursively(next_subtopic, end, sub_node->second, packet); | 94 | publishRecursively(next_subtopic, end, sub_node->second, packet); |
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | const auto plus_sign_node = this_node->children.find("+"); | 97 | const auto plus_sign_node = this_node->children.find("+"); |
| 97 | - | ||
| 98 | if (plus_sign_node != this_node->children.end()) | 98 | if (plus_sign_node != this_node->children.end()) |
| 99 | { | 99 | { |
| 100 | publishRecursively(next_subtopic, end, plus_sign_node->second, packet); | 100 | publishRecursively(next_subtopic, end, plus_sign_node->second, packet); |
| 101 | } | 101 | } |
| 102 | - | ||
| 103 | - const auto pound_sign_node = this_node->children.find("#"); | ||
| 104 | - | ||
| 105 | - if (pound_sign_node != this_node->children.end()) | ||
| 106 | - { | ||
| 107 | - return publishNonRecursively(packet, pound_sign_node->second->subscribers); | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - return false; | ||
| 111 | } | 102 | } |
| 112 | 103 | ||
| 113 | void SubscriptionStore::queuePacketAtSubscribers(const std::string &topic, const MqttPacket &packet, const Client_p &sender) | 104 | void SubscriptionStore::queuePacketAtSubscribers(const std::string &topic, const MqttPacket &packet, const Client_p &sender) |
subscriptionstore.h
| @@ -42,8 +42,8 @@ class SubscriptionStore | @@ -42,8 +42,8 @@ class SubscriptionStore | ||
| 42 | pthread_rwlock_t retainedMessagesRwlock = PTHREAD_RWLOCK_INITIALIZER; | 42 | pthread_rwlock_t retainedMessagesRwlock = PTHREAD_RWLOCK_INITIALIZER; |
| 43 | std::unordered_set<RetainedMessage> retainedMessages; | 43 | std::unordered_set<RetainedMessage> retainedMessages; |
| 44 | 44 | ||
| 45 | - bool publishNonRecursively(const MqttPacket &packet, const std::forward_list<std::string> &subscribers) const; | ||
| 46 | - bool publishRecursively(std::list<std::string>::const_iterator cur_subtopic_it, std::list<std::string>::const_iterator end, | 45 | + void publishNonRecursively(const MqttPacket &packet, const std::forward_list<std::string> &subscribers) const; |
| 46 | + void publishRecursively(std::list<std::string>::const_iterator cur_subtopic_it, std::list<std::string>::const_iterator end, | ||
| 47 | std::unique_ptr<SubscriptionNode> &next, const MqttPacket &packet) const; | 47 | std::unique_ptr<SubscriptionNode> &next, const MqttPacket &packet) const; |
| 48 | public: | 48 | public: |
| 49 | SubscriptionStore(); | 49 | SubscriptionStore(); |