Skip to content

Commit

Permalink
Avoid duplicate map lookups in correctIndices()
Browse files Browse the repository at this point in the history
  • Loading branch information
guitargeek committed Apr 9, 2024
1 parent 80313ec commit 6a9b45c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/common_details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ void fastforest::detail::correctIndices(std::vector<int>::iterator begin,
fastforest::detail::IndexMap const& nodeIndices,
fastforest::detail::IndexMap const& leafIndices) {
for (std::vector<int>::iterator it = begin; it != end; ++it) {
if (nodeIndices.count(*it)) {
*it = nodeIndices.at(*it);
} else if (leafIndices.count(*it)) {
*it = -leafIndices.at(*it);
IndexMap::const_iterator foundNode = nodeIndices.find(*it);
if (foundNode != nodeIndices.end()) {
*it = foundNode->second;
continue;
}
IndexMap::const_iterator foundLeaf = leafIndices.find(*it);
if (foundLeaf != leafIndices.end()) {
*it = -foundLeaf->second;
continue;
} else {
throw std::runtime_error("something is wrong in the node structure");
}
Expand Down

0 comments on commit 6a9b45c

Please sign in to comment.