Skip to content

Commit

Permalink
Place most likely recursive call at the end in publishRecursively
Browse files Browse the repository at this point in the history
This helps tail call optimization. A quick profile on an optimized build
shows a reduction of about 1% program time spent on
publishRecursively(...). Not much, but it comes at no cost.
  • Loading branch information
halfgaar committed Nov 30, 2023
1 parent 8700c30 commit a7aff54
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions subscriptionstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,15 +566,16 @@ void SubscriptionStore::publishRecursively(std::vector<std::string>::const_itera
}

const auto &sub_node = this_node->children.find(cur_subtop);
if (sub_node != this_node->children.end())
{
publishRecursively(next_subtopic, end, sub_node->second.get(), targetSessions, distributionHash, senderClientId);
}

if (this_node->childrenPlus)
{
publishRecursively(next_subtopic, end, this_node->childrenPlus.get(), targetSessions, distributionHash, senderClientId);
}

if (sub_node != this_node->children.end())
{
publishRecursively(next_subtopic, end, sub_node->second.get(), targetSessions, distributionHash, senderClientId);
}
}

void SubscriptionStore::queuePacketAtSubscribers(PublishCopyFactory &copyFactory, const std::string &senderClientId, bool dollar)
Expand Down

0 comments on commit a7aff54

Please sign in to comment.