diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-06-30 13:55:14 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-07-26 16:35:29 +0300 |
commit | 427773d31a5b1ad156b923aaf44ea9d2015f5be9 (patch) | |
tree | 83a4b1ab178cc92a63e9a4461923c8c822e90a5c /src/mbgl/util/grid_index.cpp | |
parent | 4e61b2e506f31682d67708832d409d38a7cb6ac0 (diff) | |
download | qtlocation-mapboxgl-427773d31a5b1ad156b923aaf44ea9d2015f5be9.tar.gz |
[core] Micro-optimizations in geometry code
Diffstat (limited to 'src/mbgl/util/grid_index.cpp')
-rw-r--r-- | src/mbgl/util/grid_index.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/mbgl/util/grid_index.cpp b/src/mbgl/util/grid_index.cpp index cf1fcd68c9..b3afd3fdc8 100644 --- a/src/mbgl/util/grid_index.cpp +++ b/src/mbgl/util/grid_index.cpp @@ -1,5 +1,6 @@ #include <mbgl/util/grid_index.hpp> #include <mbgl/geometry/feature_index.hpp> +#include <mbgl/math/minmax.hpp> #include <unordered_set> @@ -28,9 +29,10 @@ void GridIndex<T>::insert(T&& t, const BBox& bbox) { auto cx2 = convertToCellCoord(bbox.max.x); auto cy2 = convertToCellCoord(bbox.max.y); - for (int32_t x = cx1; x <= cx2; x++) { - for (int32_t y = cy1; y <= cy2; y++) { - auto cellIndex = d * y + x; + int32_t x, y, cellIndex; + for (x = cx1; x <= cx2; ++x) { + for (y = cy1; y <= cy2; ++y) { + cellIndex = d * y + x; cells[cellIndex].push_back(uid); } } @@ -48,9 +50,10 @@ std::vector<T> GridIndex<T>::query(const BBox& queryBBox) const { auto cx2 = convertToCellCoord(queryBBox.max.x); auto cy2 = convertToCellCoord(queryBBox.max.y); - for (int32_t x = cx1; x <= cx2; x++) { - for (int32_t y = cy1; y <= cy2; y++) { - auto cellIndex = d * y + x; + int32_t x, y, cellIndex; + for (x = cx1; x <= cx2; ++x) { + for (y = cy1; y <= cy2; ++y) { + cellIndex = d * y + x; for (auto uid : cells[cellIndex]) { if (seenUids.count(uid) == 0) { seenUids.insert(uid); @@ -75,7 +78,7 @@ std::vector<T> GridIndex<T>::query(const BBox& queryBBox) const { template <class T> int32_t GridIndex<T>::convertToCellCoord(int32_t x) const { - return std::max(0.0, std::min(d - 1.0, std::floor(x * scale) + padding)); + return util::max(0.0, util::min(d - 1.0, std::floor(x * scale) + padding)); } template class GridIndex<IndexedSubfeature>; |