Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace boost::string_ref with std::string_view #6433

Merged
merged 17 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- FIXED: Fix bindings compilation issue on the latest Node. Update NAN to 2.17.0. [#6416](https://github.com/Project-OSRM/osrm-backend/pull/6416)
- CHANGED: Make edge metrics strongly typed [#6420](https://github.com/Project-OSRM/osrm-backend/pull/6420)
- FIXED: Typo in file name src/util/timed_historgram.cpp -> src/util/timed_histogram.cpp [#6428](https://github.com/Project-OSRM/osrm-backend/issues/6428)
- CHANGED: Replace boost::string_ref with std::string_view [#6433](https://github.com/Project-OSRM/osrm-backend/pull/6433)
- Routing:
- FIXED: Fix adding traffic signal penalties during compression [#6419](https://github.com/Project-OSRM/osrm-backend/pull/6419)
# 5.27.1
Expand Down
8 changes: 4 additions & 4 deletions include/engine/api/base_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class BaseAPI
{
// TODO: check forward/reverse
const auto toName = [this](const auto &phantom) {
return facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))
.to_string();
return std::string(
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)));
};
const auto noEmpty = [](const auto &name) { return !name.empty(); };

Expand Down Expand Up @@ -128,8 +128,8 @@ class BaseAPI
static_cast<float>(static_cast<double>(util::toFloating(snapped_location.lat))));

const auto toName = [this](const auto &phantom) {
return facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))
.to_string();
return std::string(
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)));
};
const auto noEmpty = [](const auto &name) { return !name.empty(); };

Expand Down
14 changes: 7 additions & 7 deletions include/engine/datafacade/contiguous_internalmem_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
extractor::Datasources *m_datasources;

std::uint32_t m_check_sum;
StringView m_data_timestamp;
std::string_view m_data_timestamp;
util::vector_view<util::Coordinate> m_coordinate_list;
extractor::PackedOSMIDsView m_osmnodeid_list;
util::vector_view<std::uint32_t> m_lane_description_offsets;
Expand Down Expand Up @@ -408,32 +408,32 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
return edge_based_node_data.GetNameID(edge_based_node_id);
}

StringView GetNameForID(const NameID id) const override final
std::string_view GetNameForID(const NameID id) const override final
{
return m_name_table.GetNameForID(id);
}

StringView GetRefForID(const NameID id) const override final
std::string_view GetRefForID(const NameID id) const override final
{
return m_name_table.GetRefForID(id);
}

StringView GetPronunciationForID(const NameID id) const override final
std::string_view GetPronunciationForID(const NameID id) const override final
{
return m_name_table.GetPronunciationForID(id);
}

StringView GetDestinationsForID(const NameID id) const override final
std::string_view GetDestinationsForID(const NameID id) const override final
{
return m_name_table.GetDestinationsForID(id);
}

StringView GetExitsForID(const NameID id) const override final
std::string_view GetExitsForID(const NameID id) const override final
{
return m_name_table.GetExitsForID(id);
}

StringView GetDatasourceName(const DatasourceID id) const override final
std::string_view GetDatasourceName(const DatasourceID id) const override final
{
return m_datasources->GetSourceName(id);
}
Expand Down
16 changes: 7 additions & 9 deletions include/engine/datafacade/datafacade_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "util/integer_range.hpp"
#include "util/packed_vector.hpp"
#include "util/string_util.hpp"
#include "util/string_view.hpp"
#include "util/typedefs.hpp"

#include "osrm/coordinate.hpp"
Expand All @@ -37,6 +36,7 @@

#include <engine/bearing.hpp>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

Expand All @@ -47,8 +47,6 @@ namespace engine
namespace datafacade
{

using StringView = util::StringView;

class BaseDataFacade
{
public:
Expand Down Expand Up @@ -113,7 +111,7 @@ class BaseDataFacade
GetUncompressedReverseDatasources(const PackedGeometryID id) const = 0;

// Gets the name of a datasource
virtual StringView GetDatasourceName(const DatasourceID id) const = 0;
virtual std::string_view GetDatasourceName(const DatasourceID id) const = 0;

virtual osrm::guidance::TurnInstruction
GetTurnInstructionForEdgeID(const EdgeID edge_based_edge_id) const = 0;
Expand Down Expand Up @@ -157,15 +155,15 @@ class BaseDataFacade

virtual NameID GetNameIndex(const NodeID edge_based_node_id) const = 0;

virtual StringView GetNameForID(const NameID id) const = 0;
virtual std::string_view GetNameForID(const NameID id) const = 0;

virtual StringView GetRefForID(const NameID id) const = 0;
virtual std::string_view GetRefForID(const NameID id) const = 0;

virtual StringView GetPronunciationForID(const NameID id) const = 0;
virtual std::string_view GetPronunciationForID(const NameID id) const = 0;

virtual StringView GetDestinationsForID(const NameID id) const = 0;
virtual std::string_view GetDestinationsForID(const NameID id) const = 0;

virtual StringView GetExitsForID(const NameID id) const = 0;
virtual std::string_view GetExitsForID(const NameID id) const = 0;

virtual bool GetContinueStraightDefault() const = 0;

Expand Down
4 changes: 2 additions & 2 deletions include/engine/guidance/assemble_leg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ inline std::string assembleSummary(const datafacade::BaseDataFacade &facade,
const auto name_id_to_string = [&](const NameID name_id) {
const auto name = facade.GetNameForID(name_id);
if (!name.empty())
return name.to_string();
return std::string(name);
else
{
const auto ref = facade.GetRefForID(name_id);
return ref.to_string();
return std::string(ref);
}
};

Expand Down
40 changes: 20 additions & 20 deletions include/engine/guidance/assemble_steps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
steps.push_back(RouteStep{path_point.from_edge_based_node,
step_name_id,
is_segregated,
name.to_string(),
ref.to_string(),
pronunciation.to_string(),
destinations.to_string(),
exits.to_string(),
std::string(name),
std::string(ref),
std::string(pronunciation),
std::string(destinations),
std::string(exits),
NO_ROTARY_NAME,
NO_ROTARY_NAME,
from_alias<double>(segment_duration) / 10.,
Expand Down Expand Up @@ -241,11 +241,11 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
steps.push_back(RouteStep{leg_data[leg_data.size() - 1].from_edge_based_node,
step_name_id,
is_segregated,
facade.GetNameForID(step_name_id).to_string(),
facade.GetRefForID(step_name_id).to_string(),
facade.GetPronunciationForID(step_name_id).to_string(),
facade.GetDestinationsForID(step_name_id).to_string(),
facade.GetExitsForID(step_name_id).to_string(),
std::string(facade.GetNameForID(step_name_id)),
std::string(facade.GetRefForID(step_name_id)),
std::string(facade.GetPronunciationForID(step_name_id)),
std::string(facade.GetDestinationsForID(step_name_id)),
std::string(facade.GetExitsForID(step_name_id)),
NO_ROTARY_NAME,
NO_ROTARY_NAME,
from_alias<double>(duration) / 10.,
Expand Down Expand Up @@ -287,11 +287,11 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
steps.push_back(RouteStep{source_node_id,
source_name_id,
is_segregated,
facade.GetNameForID(source_name_id).to_string(),
facade.GetRefForID(source_name_id).to_string(),
facade.GetPronunciationForID(source_name_id).to_string(),
facade.GetDestinationsForID(source_name_id).to_string(),
facade.GetExitsForID(source_name_id).to_string(),
std::string(facade.GetNameForID(source_name_id)),
std::string(facade.GetRefForID(source_name_id)),
std::string(facade.GetPronunciationForID(source_name_id)),
std::string(facade.GetDestinationsForID(source_name_id)),
std::string(facade.GetExitsForID(source_name_id)),
NO_ROTARY_NAME,
NO_ROTARY_NAME,
from_alias<double>(duration) / 10.,
Expand Down Expand Up @@ -330,11 +330,11 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
steps.push_back(RouteStep{target_node_id,
target_name_id,
facade.IsSegregated(target_node_id),
facade.GetNameForID(target_name_id).to_string(),
facade.GetRefForID(target_name_id).to_string(),
facade.GetPronunciationForID(target_name_id).to_string(),
facade.GetDestinationsForID(target_name_id).to_string(),
facade.GetExitsForID(target_name_id).to_string(),
std::string(facade.GetNameForID(target_name_id)),
std::string(facade.GetRefForID(target_name_id)),
std::string(facade.GetPronunciationForID(target_name_id)),
std::string(facade.GetDestinationsForID(target_name_id)),
std::string(facade.GetExitsForID(target_name_id)),
NO_ROTARY_NAME,
NO_ROTARY_NAME,
ZERO_DURATION,
Expand Down
11 changes: 7 additions & 4 deletions include/extractor/datasources.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#ifndef OSRM_EXTRACT_DATASOURCES_HPP
#define OSRM_EXTRACT_DATASOURCES_HPP

#include "util/typedefs.hpp"

#include <algorithm>
#include <array>
#include <cstdint>
#include <util/string_view.hpp>
#include <util/typedefs.hpp>
#include <string_view>

namespace osrm
{
Expand All @@ -22,11 +25,11 @@ class Datasources
std::fill(sources.begin(), sources.end(), '\0');
}

util::StringView GetSourceName(DatasourceID id) const
std::string_view GetSourceName(DatasourceID id) const
{
auto begin = sources.data() + (MAX_LENGTH_NAME * id);

return util::StringView{begin, lengths[id]};
return std::string_view{begin, lengths[id]};
}

void SetSourceName(DatasourceID id, const std::string &name)
Expand Down
14 changes: 7 additions & 7 deletions include/extractor/name_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#define OSRM_EXTRACTOR_NAME_TABLE_HPP

#include "util/indexed_data.hpp"
#include "util/string_view.hpp"
#include "util/typedefs.hpp"

#include <string>
#include <string_view>

namespace osrm
{
Expand Down Expand Up @@ -50,39 +50,39 @@ template <storage::Ownership Ownership> class NameTableImpl
{
public:
using IndexedData =
util::detail::IndexedDataImpl<util::VariableGroupBlock<16, util::StringView>, Ownership>;
util::detail::IndexedDataImpl<util::VariableGroupBlock<16, std::string_view>, Ownership>;
using ResultType = typename IndexedData::ResultType;
using ValueType = typename IndexedData::ValueType;

NameTableImpl() {}

NameTableImpl(IndexedData indexed_data_) : indexed_data{std::move(indexed_data_)} {}

util::StringView GetNameForID(const NameID id) const
std::string_view GetNameForID(const NameID id) const
{
if (id == INVALID_NAMEID)
return {};

return indexed_data.at(id + 0);
}

util::StringView GetDestinationsForID(const NameID id) const
std::string_view GetDestinationsForID(const NameID id) const
{
if (id == INVALID_NAMEID)
return {};

return indexed_data.at(id + 1);
}

util::StringView GetExitsForID(const NameID id) const
std::string_view GetExitsForID(const NameID id) const
{
if (id == INVALID_NAMEID)
return {};

return indexed_data.at(id + 4);
}

util::StringView GetRefForID(const NameID id) const
std::string_view GetRefForID(const NameID id) const
{
if (id == INVALID_NAMEID)
return {};
Expand All @@ -91,7 +91,7 @@ template <storage::Ownership Ownership> class NameTableImpl
return indexed_data.at(id + OFFSET_REF);
}

util::StringView GetPronunciationForID(const NameID id) const
std::string_view GetPronunciationForID(const NameID id) const
{
if (id == INVALID_NAMEID)
return {};
Expand Down
8 changes: 4 additions & 4 deletions include/extractor/suffix_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define OSRM_EXTRACTOR_SUFFIX_LIST_HPP_

#include <string>
#include <string_view>
#include <unordered_set>

#include "util/string_view.hpp"
#include <vector>

namespace osrm
{
Expand All @@ -23,7 +23,7 @@ class SuffixTable final

// check whether a string is part of the know suffix list
bool isSuffix(const std::string &possible_suffix) const;
bool isSuffix(util::StringView possible_suffix) const;
bool isSuffix(std::string_view possible_suffix) const;

private:
// Store lower-cased strings in SuffixTable and a set of StringViews for quick membership
Expand All @@ -36,7 +36,7 @@ class SuffixTable final
// require us to first convert StringViews into strings (allocation), do the membership,
// and destroy the StringView again.
std::vector<std::string> suffixes;
std::unordered_set<util::StringView> suffix_set;
std::unordered_set<std::string_view> suffix_set;
};

} /* namespace extractor */
Expand Down
2 changes: 1 addition & 1 deletion include/storage/view_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ inline auto make_partition_view(const SharedDataIndex &index, const std::string

inline auto make_timestamp_view(const SharedDataIndex &index, const std::string &name)
{
return util::StringView(index.GetBlockPtr<char>(name), index.GetBlockEntries(name));
return std::string_view(index.GetBlockPtr<char>(name), index.GetBlockEntries(name));
}

inline auto make_cell_storage_view(const SharedDataIndex &index, const std::string &name)
Expand Down
Loading