From 5620cea82e9f274a0ceddbabca7759f321c58048 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 11 May 2016 14:57:14 -0700 Subject: [core] Avoid instantiating temporary vector --- src/mbgl/text/collision_tile.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'src/mbgl/text') diff --git a/src/mbgl/text/collision_tile.cpp b/src/mbgl/text/collision_tile.cpp index e0bc35c1fb..a7741d259a 100644 --- a/src/mbgl/text/collision_tile.cpp +++ b/src/mbgl/text/collision_tile.cpp @@ -156,30 +156,31 @@ Box CollisionTile::getTreeBox(const Point& anchor, const CollisionBox& bo std::vector CollisionTile::queryRenderedSymbols(const float minX, const float minY, const float maxX, const float maxY, const float scale) { std::vector result; + std::unordered_map> sourceLayerFeatures; auto anchor = util::matrixMultiply(rotationMatrix, Point(minX, minY)); CollisionBox queryBox(anchor, 0, 0, maxX - minX, maxY - minY, scale); - - std::vector blockingBoxes; - tree.query(bgi::intersects(getTreeBox(anchor, queryBox)), std::back_inserter(blockingBoxes)); - ignoredTree.query(bgi::intersects(getTreeBox(anchor, queryBox)), std::back_inserter(blockingBoxes)); - - std::unordered_map> sourceLayerFeatures; - - for (auto& blockingTreeBox : blockingBoxes) { - const auto& blocking = std::get<1>(blockingTreeBox); - const auto& indexedFeature = std::get<2>(blockingTreeBox); - - auto& seenFeatures = sourceLayerFeatures[indexedFeature.sourceLayerName]; - if (seenFeatures.find(indexedFeature.index) == seenFeatures.end()) { - auto blockingAnchor = util::matrixMultiply(rotationMatrix, blocking.anchor); - float minPlacementScale = findPlacementScale(minScale, anchor, queryBox, blockingAnchor, blocking); - if (minPlacementScale >= scale) { - seenFeatures.insert(indexedFeature.index); - result.push_back(indexedFeature); + auto predicates = bgi::intersects(getTreeBox(anchor, queryBox)); + + auto fn = [&] (const Tree& tree_) { + for (auto it = tree_.qbegin(predicates); it != tree_.qend(); ++it) { + const CollisionBox& blocking = std::get<1>(*it); + const IndexedSubfeature& indexedFeature = std::get<2>(*it); + + auto& seenFeatures = sourceLayerFeatures[indexedFeature.sourceLayerName]; + if (seenFeatures.find(indexedFeature.index) == seenFeatures.end()) { + auto blockingAnchor = util::matrixMultiply(rotationMatrix, blocking.anchor); + float minPlacementScale = findPlacementScale(minScale, anchor, queryBox, blockingAnchor, blocking); + if (minPlacementScale >= scale) { + seenFeatures.insert(indexedFeature.index); + result.push_back(indexedFeature); + } } } - } + }; + + fn(tree); + fn(ignoredTree); return result; } -- cgit v1.2.1