Skip to content

Commit

Permalink
Optimize RestrictionParser performance
Browse files Browse the repository at this point in the history
  • Loading branch information
SiarheiFedartsou committed Aug 28, 2022
1 parent 01e2a2d commit 6a8439e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
56 changes: 56 additions & 0 deletions include/extractor/node_location.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef QUERY_NODE_HPP
#define QUERY_NODE_HPP

#include "util/typedefs.hpp"

#include "util/coordinate.hpp"

#include <cstdint>
#include <limits>

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<value_type>::max()}, lat{std::numeric_limits<value_type>::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<value_type>(-180 * COORDINATE_PRECISION)},
util::FixedLatitude{static_cast<value_type>(-90 * COORDINATE_PRECISION)},
MIN_OSM_NODEID);
}

static NodeLocation max_value()
{
return NodeLocation(
util::FixedLongitude{static_cast<value_type>(180 * COORDINATE_PRECISION)},
util::FixedLatitude{static_cast<value_type>(90 * COORDINATE_PRECISION)},
MAX_OSM_NODEID);
}
};
} // namespace extractor
} // namespace osrm

#endif // QUERY_NODE_HPP
4 changes: 2 additions & 2 deletions include/extractor/restriction_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

#include <boost/optional/optional.hpp>

#include <string>
#include <osmium/tags/filter.hpp>
#include <set>
#include <string>
#include <vector>
#include <osmium/tags/filter.hpp>

namespace osmium
{
Expand Down
21 changes: 14 additions & 7 deletions src/extractor/restriction_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6a8439e

Please sign in to comment.