Minor optimizations (#2091)
This commit is contained in:
@@ -98,6 +98,8 @@ public:
|
||||
v.clear();
|
||||
}
|
||||
|
||||
void reserve(std::size_t count) { v.reserve(count); }
|
||||
|
||||
/// Indicate that this shared vertex vector instance will no longer be updated.
|
||||
void release() {
|
||||
#if MLN_DRAWABLE_RENDERER
|
||||
|
||||
@@ -146,6 +146,9 @@ void addDynamicAttributes(const Point<float>& anchorPoint,
|
||||
|
||||
void hideGlyphs(size_t numGlyphs, gfx::VertexVector<gfx::Vertex<SymbolDynamicLayoutAttributes>>& dynamicVertexArray) {
|
||||
const Point<float> offscreenPoint = {-INFINITY, -INFINITY};
|
||||
if (dynamicVertexArray.empty()) {
|
||||
dynamicVertexArray.reserve(4 * numGlyphs);
|
||||
}
|
||||
for (size_t i = 0; i < numGlyphs; i++) {
|
||||
addDynamicAttributes(offscreenPoint, 0, dynamicVertexArray);
|
||||
}
|
||||
@@ -270,7 +273,6 @@ std::optional<std::pair<PlacedGlyph, PlacedGlyph>> placeFirstAndLastGlyph(const
|
||||
|
||||
const float firstGlyphOffset = symbol.glyphOffsets.front();
|
||||
const float lastGlyphOffset = symbol.glyphOffsets.back();
|
||||
;
|
||||
|
||||
std::optional<PlacedGlyph> firstPlacedGlyph = placeGlyphAlongLine(fontScale * firstGlyphOffset,
|
||||
lineOffsetX,
|
||||
@@ -365,6 +367,7 @@ PlacementResult placeGlyphsAlongLine(const PlacedSymbol& symbol,
|
||||
}
|
||||
}
|
||||
|
||||
placedGlyphs.reserve(symbol.glyphOffsets.size());
|
||||
placedGlyphs.push_back(firstAndLastGlyph->first);
|
||||
for (size_t glyphIndex = 1; glyphIndex < symbol.glyphOffsets.size() - 1; glyphIndex++) {
|
||||
const float glyphOffsetX = symbol.glyphOffsets[glyphIndex];
|
||||
@@ -429,6 +432,9 @@ PlacementResult placeGlyphsAlongLine(const PlacedSymbol& symbol,
|
||||
// The number of placedGlyphs must equal the number of glyphOffsets, which
|
||||
// must correspond to the number of glyph vertices There may be 0 glyphs
|
||||
// here, if a label consists entirely of glyphs that have 0x0 dimensions
|
||||
if (dynamicVertexArray.empty()) {
|
||||
dynamicVertexArray.reserve(4 * placedGlyphs.size());
|
||||
}
|
||||
for (auto& placedGlyph : placedGlyphs) {
|
||||
addDynamicAttributes(placedGlyph.point, placedGlyph.angle, dynamicVertexArray);
|
||||
}
|
||||
|
||||
@@ -215,8 +215,6 @@ void RenderBackgroundLayer::update(gfx::ShaderRegistry& shaders,
|
||||
const std::shared_ptr<UpdateParameters>&,
|
||||
[[maybe_unused]] const RenderTree& renderTree,
|
||||
[[maybe_unused]] UniqueChangeRequestVec& changes) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
const auto zoom = state.getIntegerZoom();
|
||||
const auto tileCover = util::tileCover(state, zoom);
|
||||
|
||||
|
||||
@@ -276,8 +276,6 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
|
||||
[[maybe_unused]] const std::shared_ptr<UpdateParameters>&,
|
||||
[[maybe_unused]] const RenderTree& renderTree,
|
||||
UniqueChangeRequestVec& changes) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
if (!renderTiles || renderTiles->empty()) {
|
||||
removeAllDrawables();
|
||||
return;
|
||||
|
||||
@@ -65,8 +65,6 @@ void RenderCustomDrawableLayer::update(gfx::ShaderRegistry& shaders,
|
||||
const std::shared_ptr<UpdateParameters>& updateParameters,
|
||||
const RenderTree& renderTree,
|
||||
UniqueChangeRequestVec& changes) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
// check if host changed and update
|
||||
bool hostChanged = (host != impl(baseImpl).host);
|
||||
if (hostChanged) {
|
||||
|
||||
@@ -125,8 +125,6 @@ void RenderCustomLayer::update([[maybe_unused]] gfx::ShaderRegistry& shaders,
|
||||
const std::shared_ptr<UpdateParameters>&,
|
||||
[[maybe_unused]] const RenderTree& renderTree,
|
||||
[[maybe_unused]] UniqueChangeRequestVec& changes) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
// create layer group
|
||||
if (!layerGroup) {
|
||||
if (auto layerGroup_ = context.createLayerGroup(layerIndex, /*initialCapacity=*/1, getID())) {
|
||||
|
||||
@@ -400,8 +400,6 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
|
||||
const std::shared_ptr<UpdateParameters>&,
|
||||
[[maybe_unused]] const RenderTree& renderTree,
|
||||
[[maybe_unused]] UniqueChangeRequestVec& changes) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
if (!renderTiles || renderTiles->empty()) {
|
||||
removeAllDrawables();
|
||||
return;
|
||||
|
||||
@@ -292,8 +292,6 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
|
||||
const std::shared_ptr<UpdateParameters>&,
|
||||
[[maybe_unused]] const RenderTree& renderTree,
|
||||
UniqueChangeRequestVec& changes) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
if (!renderTiles || renderTiles->empty()) {
|
||||
removeAllDrawables();
|
||||
return;
|
||||
|
||||
@@ -304,8 +304,6 @@ void RenderHillshadeLayer::update(gfx::ShaderRegistry& shaders,
|
||||
const std::shared_ptr<UpdateParameters>&,
|
||||
[[maybe_unused]] const RenderTree& renderTree,
|
||||
UniqueChangeRequestVec& changes) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
if (!renderTiles || renderTiles->empty()) {
|
||||
removeAllDrawables();
|
||||
return;
|
||||
|
||||
@@ -353,8 +353,6 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
|
||||
const std::shared_ptr<UpdateParameters>&,
|
||||
[[maybe_unused]] const RenderTree& renderTree,
|
||||
[[maybe_unused]] UniqueChangeRequestVec& changes) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
if (!renderTiles || renderTiles->empty()) {
|
||||
removeAllDrawables();
|
||||
return;
|
||||
|
||||
@@ -256,8 +256,6 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
|
||||
const std::shared_ptr<UpdateParameters>&,
|
||||
[[maybe_unused]] const RenderTree& renderTree,
|
||||
[[maybe_unused]] UniqueChangeRequestVec& changes) {
|
||||
std::unique_lock<std::mutex> guard(mutex);
|
||||
|
||||
if ((!renderTiles || renderTiles->empty()) && !imageData) {
|
||||
if (layerGroup) {
|
||||
stats.drawablesRemoved += layerGroup->clearDrawables();
|
||||
|
||||
@@ -302,8 +302,6 @@ protected:
|
||||
// Current renderable status as specified by the markLayerRenderable event
|
||||
bool isRenderable{false};
|
||||
|
||||
std::mutex mutex;
|
||||
|
||||
struct Stats {
|
||||
size_t propertyEvaluations = 0;
|
||||
size_t drawablesAdded = 0;
|
||||
|
||||
Reference in New Issue
Block a user