speed up xml map loading
This commit is contained in:
parent
5f3e11c33a
commit
d0a509ccf4
4 changed files with 38 additions and 32 deletions
|
@ -29,6 +29,7 @@
|
|||
|
||||
// stl
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
namespace mapnik { namespace util {
|
||||
|
||||
|
@ -38,6 +39,29 @@ to avoid the compile time overhead given it is included
|
|||
by many other headers inside mapnik.
|
||||
*/
|
||||
|
||||
MAPNIK_DECL inline bool string2bool(std::string const& value, bool & result)
|
||||
{
|
||||
if (value == "true") {
|
||||
return result = true;
|
||||
} else if (value == "false") {
|
||||
result = false;
|
||||
return true;
|
||||
}
|
||||
std::string val(value);
|
||||
std::transform(val.begin(), val.end(), val.begin(), ::tolower);
|
||||
if (val == "true" || val == "yes" || val == "1" || val == "on") {
|
||||
return result = true;
|
||||
}
|
||||
result = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
MAPNIK_DECL inline bool string2bool(const char * iter, const char * end, bool & result)
|
||||
{
|
||||
std::string val(iter,end);
|
||||
return string2bool(val,result);
|
||||
}
|
||||
|
||||
MAPNIK_DECL bool string2bool(std::string const& value, bool & result);
|
||||
MAPNIK_DECL bool string2bool(const char * iter, const char * end, bool & result);
|
||||
|
||||
|
|
|
@ -180,7 +180,18 @@ 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)
|
||||
{
|
||||
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::make_pair(source,expr));
|
||||
return expr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/xml_node.hpp>
|
||||
#include <mapnik/expression.hpp>
|
||||
#include <mapnik/expression_grammar.hpp>
|
||||
#include <mapnik/path_expression_grammar.hpp>
|
||||
#include <mapnik/transform_expression_grammar.hpp>
|
||||
|
@ -52,6 +53,7 @@ private:
|
|||
std::string file_;
|
||||
transcoder tr_;
|
||||
public:
|
||||
mutable std::map<std::string,mapnik::expression_ptr> expr_cache_;
|
||||
mapnik::css_color_grammar<std::string::const_iterator> color_grammar;
|
||||
mapnik::expression_grammar<std::string::const_iterator> expr_grammar;
|
||||
path_expression_grammar<std::string::const_iterator> path_expr_grammar;
|
||||
|
|
|
@ -65,37 +65,6 @@ BOOST_SPIRIT_AUTO(qi, LONGLONG, qi::long_long)
|
|||
BOOST_SPIRIT_AUTO(qi, FLOAT, qi::float_)
|
||||
BOOST_SPIRIT_AUTO(qi, DOUBLE, qi::double_)
|
||||
|
||||
struct bool_symbols : qi::symbols<char,bool>
|
||||
{
|
||||
bool_symbols()
|
||||
{
|
||||
add("true",true)
|
||||
("false",false)
|
||||
("yes",true)
|
||||
("no",false)
|
||||
("on",true)
|
||||
("off",false)
|
||||
("1",true)
|
||||
("0",false);
|
||||
}
|
||||
};
|
||||
|
||||
bool string2bool(const char * iter, const char * end, bool & result)
|
||||
{
|
||||
using boost::spirit::qi::no_case;
|
||||
bool r = qi::phrase_parse(iter,end, no_case[bool_symbols()] ,ascii::space,result);
|
||||
return r && (iter == end);
|
||||
}
|
||||
|
||||
bool string2bool(std::string const& value, bool & result)
|
||||
{
|
||||
using boost::spirit::qi::no_case;
|
||||
std::string::const_iterator str_beg = value.begin();
|
||||
std::string::const_iterator str_end = value.end();
|
||||
bool r = qi::phrase_parse(str_beg,str_end,no_case[bool_symbols()],ascii::space,result);
|
||||
return r && (str_beg == str_end);
|
||||
}
|
||||
|
||||
bool string2int(const char * iter, const char * end, int & result)
|
||||
{
|
||||
bool r = qi::phrase_parse(iter,end,INTEGER,ascii::space,result);
|
||||
|
|
Loading…
Add table
Reference in a new issue