Merge branch 'master' of github.com:mapnik/mapnik into map-request

This commit is contained in:
Dane Springmeyer 2013-02-21 14:40:07 -08:00
commit 7c4186b09f
3 changed files with 220 additions and 24 deletions

View file

@ -14,6 +14,7 @@
#include <set>
// boost
#include <boost/version.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/bind.hpp>
@ -392,6 +393,204 @@ struct test8
}
};
#include <mapnik/rule_cache.hpp>
#if BOOST_VERSION >= 105300
#include <boost/container/vector.hpp>
#include <boost/move/utility.hpp>
class rule_cache_move
{
private:
BOOST_MOVABLE_BUT_NOT_COPYABLE(rule_cache_move)
public:
typedef std::vector<rule const*> rule_ptrs;
rule_cache_move()
: if_rules_(),
else_rules_(),
also_rules_() {}
rule_cache_move(BOOST_RV_REF(rule_cache_move) 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_move& operator=(BOOST_RV_REF(rule_cache_move) 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())
{
else_rules_.push_back(&r);
}
else if (r.has_also_filter())
{
also_rules_.push_back(&r);
}
else
{
if_rules_.push_back(&r);
}
}
rule_ptrs const& get_if_rules() const
{
return if_rules_;
}
rule_ptrs const& get_else_rules() const
{
return else_rules_;
}
rule_ptrs const& get_also_rules() const
{
return also_rules_;
}
private:
rule_ptrs if_rules_;
rule_ptrs else_rules_;
rule_ptrs also_rules_;
};
struct test9
{
unsigned iter_;
unsigned threads_;
unsigned num_rules_;
unsigned num_styles_;
std::vector<rule> rules_;
explicit test9(unsigned iterations,
unsigned threads,
unsigned num_rules,
unsigned num_styles) :
iter_(iterations),
threads_(threads),
num_rules_(num_rules),
num_styles_(num_styles),
rules_() {
mapnik::rule r("test");
for (unsigned i=0;i<num_rules_;++i) {
rules_.push_back(r);
}
}
bool validate()
{
return true;
}
void operator()()
{
for (unsigned i=0;i<iter_;++i) {
boost::container::vector<rule_cache_move> rule_caches;
for (unsigned i=0;i<num_styles_;++i) {
rule_cache_move rc;
for (unsigned i=0;i<num_rules_;++i) {
rc.add_rule(rules_[i]);
}
rule_caches.push_back(boost::move(rc));
}
}
}
};
#endif
class rule_cache_heap
{
public:
typedef std::vector<rule const*> rule_ptrs;
rule_cache_heap()
: if_rules_(),
else_rules_(),
also_rules_() {}
void add_rule(rule const& r)
{
if (r.has_else_filter())
{
else_rules_.push_back(&r);
}
else if (r.has_also_filter())
{
also_rules_.push_back(&r);
}
else
{
if_rules_.push_back(&r);
}
}
rule_ptrs const& get_if_rules() const
{
return if_rules_;
}
rule_ptrs const& get_else_rules() const
{
return else_rules_;
}
rule_ptrs const& get_also_rules() const
{
return also_rules_;
}
private:
rule_ptrs if_rules_;
rule_ptrs else_rules_;
rule_ptrs also_rules_;
};
struct test10
{
unsigned iter_;
unsigned threads_;
unsigned num_rules_;
unsigned num_styles_;
std::vector<rule> rules_;
explicit test10(unsigned iterations,
unsigned threads,
unsigned num_rules,
unsigned num_styles) :
iter_(iterations),
threads_(threads),
num_rules_(num_rules),
num_styles_(num_styles),
rules_() {
mapnik::rule r("test");
for (unsigned i=0;i<num_rules_;++i) {
rules_.push_back(r);
}
}
bool validate()
{
return true;
}
void operator()()
{
for (unsigned i=0;i<iter_;++i) {
boost::ptr_vector<rule_cache_heap> rule_caches;
for (unsigned i=0;i<num_styles_;++i) {
std::auto_ptr<rule_cache_heap> rc(new rule_cache_heap);
for (unsigned i=0;i<num_rules_;++i) {
rc->add_rule(rules_[i]);
}
rule_caches.push_back(rc);
}
}
}
};
int main( int argc, char** argv)
{
if (argc > 0) {
@ -507,6 +706,20 @@ int main( int argc, char** argv)
benchmark(runner,"expression parsing by re-using grammar");
}
{
#if BOOST_VERSION >= 105300
test9 runner(1000,10,200,50);
benchmark(runner,"rule caching using boost::move");
#else
std::clog << "not running: 'rule caching using boost::move'\n";
#endif
}
{
test10 runner(1000,10,200,50);
benchmark(runner,"rule caching using heap allocation");
}
std::cout << "...benchmark done\n";
return 0;
}

View file

@ -51,7 +51,6 @@
#include <boost/variant/static_visitor.hpp>
#include <boost/foreach.hpp>
#include <boost/concept_check.hpp>
#include <boost/container/vector.hpp>
// stl
#include <vector>
@ -397,7 +396,8 @@ 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::container::vector<rule_cache> rule_caches;
boost::ptr_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)
{
@ -413,12 +413,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;
rule_cache rc;
std::auto_ptr<rule_cache> rc(new rule_cache);
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)
{
@ -429,7 +429,7 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
}
if (active_rules)
{
rule_caches.push_back(boost::move(rc));
rule_caches.push_back(rc);
active_styles.push_back(&(*style));
}
}

View file

@ -29,7 +29,6 @@
// boost
#include <boost/foreach.hpp>
#include <boost/move/utility.hpp>
// stl
#include <vector>
@ -39,8 +38,6 @@ namespace mapnik
class rule_cache
{
private:
BOOST_MOVABLE_BUT_NOT_COPYABLE(rule_cache)
public:
typedef std::vector<rule const*> rule_ptrs;
rule_cache()
@ -48,20 +45,6 @@ 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())
@ -82,12 +65,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_;