From 712ff50abe29c25df068315b187e1807676e7eb8 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 26 Feb 2013 10:52:41 -0500 Subject: [PATCH 1/2] make a few utility functions inline and static --- include/mapnik/util/geometry_to_ds_type.hpp | 2 +- plugins/input/csv/csv_utils.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mapnik/util/geometry_to_ds_type.hpp b/include/mapnik/util/geometry_to_ds_type.hpp index d0db1e284..cff44bc27 100644 --- a/include/mapnik/util/geometry_to_ds_type.hpp +++ b/include/mapnik/util/geometry_to_ds_type.hpp @@ -33,7 +33,7 @@ namespace mapnik { namespace util { - void to_ds_type(mapnik::geometry_container const& paths, + static inline void to_ds_type(mapnik::geometry_container const& paths, boost::optional & result) { if (paths.size() == 1) diff --git a/plugins/input/csv/csv_utils.hpp b/plugins/input/csv/csv_utils.hpp index 127837505..3fdcaa3c8 100644 --- a/plugins/input/csv/csv_utils.hpp +++ b/plugins/input/csv/csv_utils.hpp @@ -29,7 +29,7 @@ namespace csv_utils { - static void fix_json_quoting(std::string & csv_line) + static inline void fix_json_quoting(std::string & csv_line) { std::string wrapping_char; std::string::size_type j_idx = std::string::npos; From d861636fbc5c3fc1a054957b897d815fe642bebe Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 26 Feb 2013 12:07:36 -0500 Subject: [PATCH 2/2] move const char string2value interface to use iterators --- include/mapnik/util/conversions.hpp | 18 ++++++++++++------ plugins/input/postgis/postgis_datasource.cpp | 6 ++++-- src/conversions.cpp | 20 +++++--------------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/include/mapnik/util/conversions.hpp b/include/mapnik/util/conversions.hpp index 522633d4a..9c7c0a514 100644 --- a/include/mapnik/util/conversions.hpp +++ b/include/mapnik/util/conversions.hpp @@ -32,22 +32,28 @@ namespace mapnik { namespace util { -MAPNIK_DECL bool string2bool(const char * value, bool & result); -MAPNIK_DECL bool string2bool(std::string const& value, bool & result); +/* +Note: this file intentionally provides non-templated methods +to avoid the compile time overhead given it is included +by many other headers inside mapnik. +*/ + +MAPNIK_DECL bool string2bool(std::string const& value, bool & result); +MAPNIK_DECL bool string2bool(const char * iter, const char * end, bool & result); -MAPNIK_DECL bool string2int(const char * value, int & result); MAPNIK_DECL bool string2int(std::string const& value, int & result); +MAPNIK_DECL bool string2int(const char * iter, const char * end, int & result); #ifdef BIGINT -MAPNIK_DECL bool string2int(const char * value, mapnik::value_integer & result); MAPNIK_DECL bool string2int(std::string const& value, mapnik::value_integer & result); +MAPNIK_DECL bool string2int(const char * iter, const char * end, mapnik::value_integer & result); #endif MAPNIK_DECL bool string2double(std::string const& value, double & result); -MAPNIK_DECL bool string2double(const char * value, double & result); +MAPNIK_DECL bool string2double(const char * iter, const char * end, double & result); MAPNIK_DECL bool string2float(std::string const& value, float & result); -MAPNIK_DECL bool string2float(const char * value, float & result); +MAPNIK_DECL bool string2float(const char * iter, const char * end, float & result); MAPNIK_DECL bool to_string(std::string & str, int value); #ifdef BIGINT diff --git a/plugins/input/postgis/postgis_datasource.cpp b/plugins/input/postgis/postgis_datasource.cpp index 7376cca31..57b6fc907 100644 --- a/plugins/input/postgis/postgis_datasource.cpp +++ b/plugins/input/postgis/postgis_datasource.cpp @@ -178,7 +178,8 @@ postgis_datasource::postgis_datasource(parameters const& params) if (srid_c != NULL) { int result = 0; - if (mapnik::util::string2int(srid_c, result)) + const char * end = srid_c + std::strlen(srid_c); + if (mapnik::util::string2int(srid_c, end, result)) { srid_ = result; } @@ -209,7 +210,8 @@ postgis_datasource::postgis_datasource(parameters const& params) if (srid_c != NULL) { int result = 0; - if (mapnik::util::string2int(srid_c, result)) + const char * end = srid_c + std::strlen(srid_c); + if (mapnik::util::string2int(srid_c, end, result)) { srid_ = result; } diff --git a/src/conversions.cpp b/src/conversions.cpp index fe916092d..82ae88f4c 100644 --- a/src/conversions.cpp +++ b/src/conversions.cpp @@ -78,11 +78,9 @@ struct bool_symbols : qi::symbols } }; -bool string2bool(const char * value, bool & result) +bool string2bool(const char * iter, const char * end, bool & result) { using boost::spirit::qi::no_case; - const char *iter = value; - const char *end = value + std::strlen(value); bool r = qi::phrase_parse(iter,end, no_case[bool_symbols()] ,ascii::space,result); return r && (iter == end); } @@ -96,10 +94,8 @@ bool string2bool(std::string const& value, bool & result) return r && (str_beg == str_end); } -bool string2int(const char * value, int & result) +bool string2int(const char * iter, const char * end, int & result) { - const char *iter = value; - const char *end = value + std::strlen(value); bool r = qi::phrase_parse(iter,end,INTEGER,ascii::space,result); return r && (iter == end); } @@ -113,10 +109,8 @@ bool string2int(std::string const& value, int & result) } #ifdef BIGINT -bool string2int(const char * value, mapnik::value_integer & result) +bool string2int(const char * iter, const char * end, mapnik::value_integer & result) { - const char *iter = value; - const char *end = value + std::strlen(value); bool r = qi::phrase_parse(iter,end,LONGLONG,ascii::space,result); return r && (iter == end); } @@ -138,10 +132,8 @@ bool string2double(std::string const& value, double & result) return r && (str_beg == str_end); } -bool string2double(const char * value, double & result) +bool string2double(const char * iter, const char * end, double & result) { - const char *iter = value; - const char *end = value + std::strlen(value); bool r = qi::phrase_parse(iter,end,DOUBLE,ascii::space,result); return r && (iter == end); } @@ -154,10 +146,8 @@ bool string2float(std::string const& value, float & result) return r && (str_beg == str_end); } -bool string2float(const char * value, float & result) +bool string2float(const char * iter, const char * end, float & result) { - const char *iter = value; - const char *end = value + std::strlen(value); bool r = qi::phrase_parse(iter,end,FLOAT,ascii::space,result); return r && (iter == end); }