summaryrefslogtreecommitdiff
path: root/src/mbgl/text
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-05-11 14:57:14 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-05-12 08:36:30 -0700
commit5620cea82e9f274a0ceddbabca7759f321c58048 (patch)
tree98046dd1485c9dd8469ac53211f40697c770abb3 /src/mbgl/text
parentb87fe1616991e1dc454c9bfc74ec68caff0b7062 (diff)
downloadqtlocation-mapboxgl-5620cea82e9f274a0ceddbabca7759f321c58048.tar.gz
[core] Avoid instantiating temporary vector
Diffstat (limited to 'src/mbgl/text')
-rw-r--r--src/mbgl/text/collision_tile.cpp39
1 files changed, 20 insertions, 19 deletions
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<float>& anchor, const CollisionBox& bo
std::vector<IndexedSubfeature> CollisionTile::queryRenderedSymbols(const float minX, const float minY, const float maxX, const float maxY, const float scale) {
std::vector<IndexedSubfeature> result;
+ std::unordered_map<std::string, std::set<std::size_t>> sourceLayerFeatures;
auto anchor = util::matrixMultiply(rotationMatrix, Point<float>(minX, minY));
CollisionBox queryBox(anchor, 0, 0, maxX - minX, maxY - minY, scale);
-
- std::vector<CollisionTreeBox> 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<std::string, std::set<std::size_t>> 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;
}