From 05657e9573cdb01242a4e8365817be3f8bb62618 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Thu, 12 Mar 2020 21:46:29 +0200 Subject: [PATCH] [core] Binary size fixup --- src/mbgl/text/placement.cpp | 84 ++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index 4eaf08f34..fff11ab18 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -592,7 +592,8 @@ void Placement::placeSymbolBucket(const BucketPlacementData& params, std::set shift) -> bool { + auto collisionBoxIntersectsTileEdges = [&](const CollisionBox& collisionBox, + Point shift) noexcept->bool { bool intersects = collisionIndex.intersectsTileEdges(collisionBox, shift, renderTile.matrix, pixelRatio, *tileBorders); // Check if this symbol intersects the neighbor tile borders. If so, it also shall be placed with priority. @@ -604,7 +605,14 @@ void Placement::placeSymbolBucket(const BucketPlacementData& params, std::set bool { + auto symbolIntersectsTileEdges = [ + &locationCache, + &collisionBoxIntersectsTileEdges, + variableAnchor, + pitchTextWithMap, + rotateTextWithMap, + bearing = state.getBearing() + ](const SymbolInstance& symbol) noexcept->bool { auto it = locationCache.find(symbol.crossTileID); if (it != locationCache.end()) return it->second; @@ -623,7 +631,7 @@ void Placement::placeSymbolBucket(const BucketPlacementData& params, std::setgetSymbolPlacement(a); - auto* bPlacement = previousPlacement->getSymbolPlacement(b); - if (!aPlacement) { - // a < b, if 'a' is new and if 'b' was previously hidden. - return bPlacement && !bPlacement->placed(); - } - if (!bPlacement) { - // a < b, if 'b' is new and 'a' was previously shown. - return aPlacement && aPlacement->placed(); - } - // a < b, if 'a' was shown and 'b' was hidden. - return aPlacement->placed() && !bPlacement->placed(); - }); + std::stable_sort( + sortedSymbols.begin(), + sortedSymbols.end(), + [previousPlacement](const SymbolInstance& a, const SymbolInstance& b) noexcept { + auto* aPlacement = previousPlacement->getSymbolPlacement(a); + auto* bPlacement = previousPlacement->getSymbolPlacement(b); + if (!aPlacement) { + // a < b, if 'a' is new and if 'b' was previously hidden. + return bPlacement && !bPlacement->placed(); + } + if (!bPlacement) { + // a < b, if 'b' is new and 'a' was previously shown. + return aPlacement && aPlacement->placed(); + } + // a < b, if 'a' was shown and 'b' was hidden. + return aPlacement->placed() && !bPlacement->placed(); + }); } for (const SymbolInstance& symbol : sortedSymbols) { placeSymbol(symbol); @@ -1226,8 +1235,7 @@ float Placement::zoomAdjustment(const float zoom) const { const JointPlacement* Placement::getSymbolPlacement(const SymbolInstance& symbol) const { assert(symbol.crossTileID != 0); auto found = placements.find(symbol.crossTileID); - if (found == placements.end()) return nullptr; - return &found->second; + return (found == placements.end()) ? &found->second : nullptr; } Duration Placement::getUpdatePeriod(const float zoom) const {