+ use boost::move to emulate 'move' semantics

for mapnik::rule_cache objects and avoid
  dynamically allocating them.
This commit is contained in:
artemp 2013-02-21 12:50:23 +00:00
parent df0f4a22b8
commit fe9ff21ba9
2 changed files with 24 additions and 7 deletions

View file

@ -51,6 +51,7 @@
#include <boost/variant/static_visitor.hpp>
#include <boost/foreach.hpp>
#include <boost/concept_check.hpp>
#include <boost/container/vector.hpp>
// stl
#include <vector>
@ -371,8 +372,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
attribute_collector collector(names);
double filt_factor = 1.0;
directive_collector d_collector(filt_factor);
boost::ptr_vector<rule_cache> rule_caches;
boost::container::vector<rule_cache> rule_caches;
// iterate through all named styles collecting active styles and attribute names
BOOST_FOREACH(std::string const& style_name, style_names)
{
@ -388,12 +388,12 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
std::vector<rule> const& rules = style->get_rules();
bool active_rules = false;
std::auto_ptr<rule_cache> rc(new rule_cache);
rule_cache rc;
BOOST_FOREACH(rule const& r, rules)
{
if (r.active(scale_denom))
{
rc->add_rule(r);
rc.add_rule(r);
active_rules = true;
if (ds->type() == datasource::Vector)
{
@ -404,7 +404,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
}
if (active_rules)
{
rule_caches.push_back(rc);
rule_caches.push_back(boost::move(rc));
active_styles.push_back(&(*style));
}
}

View file

@ -29,6 +29,7 @@
// boost
#include <boost/foreach.hpp>
#include <boost/move/utility.hpp>
// stl
#include <vector>
@ -38,6 +39,8 @@ namespace mapnik
class rule_cache
{
private:
BOOST_MOVABLE_BUT_NOT_COPYABLE(rule_cache)
public:
typedef std::vector<rule const*> rule_ptrs;
rule_cache()
@ -45,6 +48,20 @@ public:
else_rules_(),
also_rules_() {}
rule_cache(BOOST_RV_REF(rule_cache) rhs) // move ctor
: if_rules_(boost::move(rhs.if_rules_)),
else_rules_(boost::move(rhs.else_rules_)),
also_rules_(boost::move(rhs.also_rules_))
{}
rule_cache& operator=(BOOST_RV_REF(rule_cache) rhs) // move assign
{
std::swap(if_rules_, rhs.if_rules_);
std::swap(else_rules_,rhs.else_rules_);
std::swap(also_rules_, rhs.also_rules_);
return *this;
}
void add_rule(rule const& r)
{
if (r.has_else_filter())
@ -65,12 +82,12 @@ public:
{
return if_rules_;
}
rule_ptrs const& get_else_rules() const
{
return else_rules_;
}
rule_ptrs const& get_also_rules() const
{
return also_rules_;