From 6a8439eee8e6305099fc5ce6132732d7a38e85ba Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 28 Aug 2022 09:12:11 +0200 Subject: [PATCH] Optimize RestrictionParser performance --- include/extractor/node_location.hpp | 56 ++++++++++++++++++++++++ include/extractor/restriction_parser.hpp | 4 +- src/extractor/restriction_parser.cpp | 21 ++++++--- 3 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 include/extractor/node_location.hpp diff --git a/include/extractor/node_location.hpp b/include/extractor/node_location.hpp new file mode 100644 index 00000000000..3a923cb76ef --- /dev/null +++ b/include/extractor/node_location.hpp @@ -0,0 +1,56 @@ +#ifndef QUERY_NODE_HPP +#define QUERY_NODE_HPP + +#include "util/typedefs.hpp" + +#include "util/coordinate.hpp" + +#include +#include + +namespace osrm +{ +namespace extractor +{ + +struct NodeLocation +{ + using key_type = OSMNodeID; // type of NodeID + using value_type = std::int32_t; // type of lat,lons + + explicit NodeLocation(const util::FixedLongitude lon_, + const util::FixedLatitude lat_, + const key_type node_id_) + : lon(lon_), lat(lat_), node_id(node_id_) + { + } + NodeLocation() + : lon{std::numeric_limits::max()}, lat{std::numeric_limits::max()}, + node_id(SPECIAL_OSM_NODEID) + { + } + + util::FixedLongitude lon; + util::FixedLatitude lat; + key_type node_id; + + static NodeLocation min_value() + { + return NodeLocation( + util::FixedLongitude{static_cast(-180 * COORDINATE_PRECISION)}, + util::FixedLatitude{static_cast(-90 * COORDINATE_PRECISION)}, + MIN_OSM_NODEID); + } + + static NodeLocation max_value() + { + return NodeLocation( + util::FixedLongitude{static_cast(180 * COORDINATE_PRECISION)}, + util::FixedLatitude{static_cast(90 * COORDINATE_PRECISION)}, + MAX_OSM_NODEID); + } +}; +} // namespace extractor +} // namespace osrm + +#endif // QUERY_NODE_HPP diff --git a/include/extractor/restriction_parser.hpp b/include/extractor/restriction_parser.hpp index 6749c90bcb8..869ff9b8404 100644 --- a/include/extractor/restriction_parser.hpp +++ b/include/extractor/restriction_parser.hpp @@ -5,10 +5,10 @@ #include -#include +#include #include +#include #include -#include namespace osmium { diff --git a/src/extractor/restriction_parser.cpp b/src/extractor/restriction_parser.cpp index 90a2e0dc311..37ad2c212c9 100644 --- a/src/extractor/restriction_parser.cpp +++ b/src/extractor/restriction_parser.cpp @@ -109,7 +109,8 @@ RestrictionParser::TryParse(const osmium::Relation &relation) const { is_only_restriction = true; } - else if (boost::algorithm::starts_with(value, "no_") && !boost::algorithm::ends_with(value, "_on_red")) + else if (boost::algorithm::starts_with(value, "no_") && + !boost::algorithm::ends_with(value, "_on_red")) { is_only_restriction = false; if (boost::algorithm::starts_with(value, "no_exit")) @@ -126,7 +127,8 @@ RestrictionParser::TryParse(const osmium::Relation &relation) const return {}; } - if (parse_conditionals) { + if (parse_conditionals) + { // Parse condition and add independent value/condition pairs const auto &parsed = osrm::util::ParseConditionalRestrictions(value); @@ -158,7 +160,7 @@ RestrictionParser::TryParse(const osmium::Relation &relation) const const bool is_from_role = strcmp("from", role) == 0; const bool is_to_role = strcmp("to", role) == 0; const bool is_via_role = strcmp("via", role) == 0; - + if (!is_from_role && !is_to_role && !is_via_role) { continue; @@ -263,12 +265,17 @@ bool RestrictionParser::ShouldIgnoreRestriction(const std::string &except_tag_st // split `except_tag_string` by semicolon and check if any of items is in `restrictions` std::string current_string; - for (size_t index = 0; index < except_tag_string.size(); index++) { + for (size_t index = 0; index < except_tag_string.size(); index++) + { const auto ch = except_tag_string[index]; - if (ch != ';') { + if (ch != ';') + { current_string += ch; - } else { - if (restrictions.find(current_string) != restrictions.end()) { + } + else + { + if (restrictions.find(current_string) != restrictions.end()) + { return true; } current_string.clear();