From 745d45bb680fffe5452db52204194809f9c77c78 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 1 Oct 2014 11:22:29 +0100 Subject: [PATCH] remove std::function from placement loop (std::function incurs overhead of polymorphic dispatch internally and relatively expensive - avoid using in performance critic code) --- src/text/placement_finder.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/text/placement_finder.cpp b/src/text/placement_finder.cpp index e32304f90..b615d33bb 100644 --- a/src/text/placement_finder.cpp +++ b/src/text/placement_finder.cpp @@ -36,7 +36,6 @@ // stl #include -#include namespace mapnik { @@ -211,17 +210,22 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or double angle; rotation rot; double last_glyph_spacing = 0.; - std::function glyph_move_method = std::bind( - move_by_length ? &vertex_cache::move : &vertex_cache::move_to_distance, &off_pp, std::placeholders::_1); for (auto const& glyph : line) { if (current_cluster != static_cast(glyph.char_index)) { - if (!glyph_move_method(sign * (layout.cluster_width(current_cluster) + last_glyph_spacing))) + if (move_by_length) { - return false; + if (!off_pp.move(sign * (layout.cluster_width(current_cluster) + last_glyph_spacing))) + return false; } + else + { + if (!off_pp.move_to_distance(sign * (layout.cluster_width(current_cluster) + last_glyph_spacing))) + return false; + } + current_cluster = glyph.char_index; last_glyph_spacing = glyph.format->character_spacing * scale_factor_; // Only calculate new angle at the start of each cluster!