cache result of parse_expression to speed up map loading - refs #1167
This commit is contained in:
parent
ef837eb92f
commit
ad10497503
4 changed files with 43 additions and 8 deletions
|
@ -26,4 +26,31 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BENCHMARK(test,"string->bool")
|
class test2 : public benchmark::test_case
|
||||||
|
{
|
||||||
|
std::string value_;
|
||||||
|
public:
|
||||||
|
test2(mapnik::parameters const& params)
|
||||||
|
: test_case(params),
|
||||||
|
value_("1.23456789") {}
|
||||||
|
bool validate() const
|
||||||
|
{
|
||||||
|
double result = 0;
|
||||||
|
mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result);
|
||||||
|
if (result != 1.23456789) return false;
|
||||||
|
result = 0;
|
||||||
|
mapnik::util::string2double(value_,result);
|
||||||
|
return (result == 1.23456789);
|
||||||
|
}
|
||||||
|
void operator()() const
|
||||||
|
{
|
||||||
|
for (std::size_t i=0;i<iterations_;++i) {
|
||||||
|
double result = 0;
|
||||||
|
mapnik::util::string2double(value_,result);
|
||||||
|
//mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//BENCHMARK(test,"string->bool")
|
||||||
|
BENCHMARK(test2,"string->double")
|
||||||
|
|
|
@ -180,7 +180,17 @@ struct do_xml_attribute_cast<mapnik::expression_ptr>
|
||||||
{
|
{
|
||||||
static inline boost::optional<mapnik::expression_ptr> xml_attribute_cast_impl(xml_tree const& tree, std::string const& source)
|
static inline boost::optional<mapnik::expression_ptr> xml_attribute_cast_impl(xml_tree const& tree, std::string const& source)
|
||||||
{
|
{
|
||||||
return parse_expression(source, tree.expr_grammar);
|
std::map<std::string,mapnik::expression_ptr>::const_iterator itr = tree.expr_cache_.find(source);
|
||||||
|
if (itr != tree.expr_cache_.end())
|
||||||
|
{
|
||||||
|
return itr->second;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mapnik::expression_ptr expr = parse_expression(source, tree.expr_grammar);
|
||||||
|
tree.expr_cache_.insert(std::move(std::make_pair(source,expr)));
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ private:
|
||||||
std::string file_;
|
std::string file_;
|
||||||
transcoder tr_;
|
transcoder tr_;
|
||||||
public:
|
public:
|
||||||
mutable std::map<std::string,mapnik::color> color_cache_;
|
|
||||||
mutable std::map<std::string,mapnik::expression_ptr> expr_cache_;
|
mutable std::map<std::string,mapnik::expression_ptr> expr_cache_;
|
||||||
mapnik::css_color_grammar<std::string::const_iterator> color_grammar;
|
mapnik::css_color_grammar<std::string::const_iterator> color_grammar;
|
||||||
mapnik::expression_grammar<std::string::const_iterator> expr_grammar;
|
mapnik::expression_grammar<std::string::const_iterator> expr_grammar;
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
UNAME=$(uname -s)
|
UNAME=$(uname -s)
|
||||||
CURRENT_DIR=$(pwd)
|
export CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
if [ ${UNAME} = 'Darwin' ]; then
|
if [ ${UNAME} = 'Darwin' ]; then
|
||||||
export DYLD_LIBRARY_PATH="${CURRENT_DIR}/src/":${DYLD_LIBRARY_PATH}
|
export DYLD_LIBRARY_PATH="${CURRENT_DIR}/src/"
|
||||||
else
|
else
|
||||||
export LD_LIBRARY_PATH="${CURRENT_DIR}/src/":${DYLD_LIBRARY_PATH}
|
export LD_LIBRARY_PATH="${CURRENT_DIR}/src/"
|
||||||
fi
|
fi
|
||||||
export PYTHONPATH="${CURRENT_DIR}/bindings/python/":${PYTHONPATH}
|
export PYTHONPATH="${CURRENT_DIR}/bindings/python/"
|
||||||
export MAPNIK_FONT_DIRECTORY="${CURRENT_DIR}/fonts/dejavu-fonts-ttf-2.33/ttf/"
|
export MAPNIK_FONT_DIRECTORY="${CURRENT_DIR}/fonts/dejavu-fonts-ttf-2.33/ttf/"
|
||||||
export MAPNIK_INPUT_PLUGINS_DIRECTORY="${CURRENT_DIR}/plugins/input/"
|
export MAPNIK_INPUT_PLUGINS_DIRECTORY="${CURRENT_DIR}/plugins/input/"
|
||||||
export PATH="${CURRENT_DIR}/bin/":${PATH}
|
export PATH="${CURRENT_DIR}/bin/":${PATH}
|
||||||
|
|
Loading…
Reference in a new issue