From 427773d31a5b1ad156b923aaf44ea9d2015f5be9 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 30 Jun 2016 13:55:14 +0300 Subject: [core] Micro-optimizations in geometry code --- src/mbgl/util/grid_index.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/mbgl/util/grid_index.cpp') 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 #include +#include #include @@ -28,9 +29,10 @@ void GridIndex::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 GridIndex::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 GridIndex::query(const BBox& queryBBox) const { template int32_t GridIndex::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; -- cgit v1.2.1