Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Performance fix for placement in tile mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pozdnyakov committed Dec 10, 2019
1 parent 5e54267 commit c8d47ab
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/mbgl/text/placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,15 @@ void Placement::placeBucket(const SymbolBucket& bucket,
symbolInstances.end());
optional<style::TextVariableAnchorType> variableAnchor;
if (!variableTextAnchors.empty()) variableAnchor = variableTextAnchors.front();
std::unordered_map<uint32_t, bool> sortedCache;
sortedCache.reserve(sorted.size());

auto intersectsTileBorder = [&](const SymbolInstance& symbol) -> bool {
if (symbol.textCollisionFeature.boxes.empty()) return false;
if (symbol.textCollisionFeature.alongLine || symbol.textCollisionFeature.boxes.empty()) return false;

auto it = sortedCache.find(symbol.crossTileID);
if (it != sortedCache.end()) return it->second;

Point<float> offset{};
if (variableAnchor) {
const CollisionBox& textBox = symbol.textCollisionFeature.boxes.front();
Expand All @@ -579,8 +585,10 @@ void Placement::placeBucket(const SymbolBucket& bucket,
pitchWithMap,
state.getBearing());
}
return collisionIndex.featureIntersectsTileBorders(
bool result = collisionIndex.featureIntersectsTileBorders(
symbol.textCollisionFeature, offset, posMatrix, pixelRatio, *tileBorders);
sortedCache.insert(std::make_pair(symbol.crossTileID, result));
return result;
};

std::stable_sort(sorted.begin(), sorted.end(), [&](const SymbolInstance& a, const SymbolInstance& b) {
Expand Down

0 comments on commit c8d47ab

Please sign in to comment.