Implements Zero-Copy String Views onto Contiguous Memory, resolves #3265.
- http://www.boost.org/doc/libs/1_61_0/libs/utility/doc/html/string_ref.html - http://en.cppreference.com/w/cpp/string/basic_string_view
This commit is contained in:
@@ -159,13 +159,14 @@ inline bool requiresNameAnnounced(const NameID from_name_id,
|
||||
if (from_name_id == to_name_id)
|
||||
return false;
|
||||
else
|
||||
return requiresNameAnnounced(name_table.GetNameForID(from_name_id),
|
||||
name_table.GetRefForID(from_name_id),
|
||||
name_table.GetPronunciationForID(from_name_id),
|
||||
name_table.GetNameForID(to_name_id),
|
||||
name_table.GetRefForID(to_name_id),
|
||||
name_table.GetPronunciationForID(to_name_id),
|
||||
return requiresNameAnnounced(name_table.GetNameForID(from_name_id).to_string(),
|
||||
name_table.GetRefForID(from_name_id).to_string(),
|
||||
name_table.GetPronunciationForID(from_name_id).to_string(),
|
||||
name_table.GetNameForID(to_name_id).to_string(),
|
||||
name_table.GetRefForID(to_name_id).to_string(),
|
||||
name_table.GetPronunciationForID(to_name_id).to_string(),
|
||||
suffix_table);
|
||||
// FIXME: converts StringViews to strings since the name change heuristics mutates in place
|
||||
}
|
||||
|
||||
inline bool requiresNameAnnounced(const NameID from_name_id,
|
||||
@@ -175,12 +176,13 @@ inline bool requiresNameAnnounced(const NameID from_name_id,
|
||||
if (from_name_id == to_name_id)
|
||||
return false;
|
||||
else
|
||||
return requiresNameAnnounced(name_table.GetNameForID(from_name_id),
|
||||
name_table.GetRefForID(from_name_id),
|
||||
name_table.GetPronunciationForID(from_name_id),
|
||||
name_table.GetNameForID(to_name_id),
|
||||
name_table.GetRefForID(to_name_id),
|
||||
name_table.GetPronunciationForID(to_name_id));
|
||||
return requiresNameAnnounced(name_table.GetNameForID(from_name_id).to_string(),
|
||||
name_table.GetRefForID(from_name_id).to_string(),
|
||||
name_table.GetPronunciationForID(from_name_id).to_string(),
|
||||
name_table.GetNameForID(to_name_id).to_string(),
|
||||
name_table.GetRefForID(to_name_id).to_string(),
|
||||
name_table.GetPronunciationForID(to_name_id).to_string());
|
||||
// FIXME: converts StringViews to strings since the name change heuristics mutates in place
|
||||
}
|
||||
|
||||
} // namespace guidance
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "util/range_table.hpp"
|
||||
#include "util/shared_memory_vector_wrapper.hpp"
|
||||
#include "util/string_view.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -28,9 +30,9 @@ class NameTable
|
||||
// The following functions are a subset of what is available.
|
||||
// See the data facades for they provide full access to this serialized string data.
|
||||
// (at time of writing this: get{Name,Ref,Pronunciation,Destinations}ForID(name_id);)
|
||||
std::string GetNameForID(const unsigned name_id) const;
|
||||
std::string GetRefForID(const unsigned name_id) const;
|
||||
std::string GetPronunciationForID(const unsigned name_id) const;
|
||||
util::StringView GetNameForID(const NameID id) const;
|
||||
util::StringView GetRefForID(const NameID id) const;
|
||||
util::StringView GetPronunciationForID(const NameID id) const;
|
||||
};
|
||||
} // namespace util
|
||||
} // namespace osrm
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef OSRM_STRING_VIEW_HPP
|
||||
#define OSRM_STRING_VIEW_HPP
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
// Convenience typedef: boost::string_ref, boost::string_view or C++17's string_view
|
||||
using StringView = boost::string_ref;
|
||||
|
||||
} // namespace util
|
||||
} // namespace osrm
|
||||
|
||||
// Specializing hash<> for user-defined type in std namespace, this is standard conforming.
|
||||
namespace std
|
||||
{
|
||||
template <> struct hash<::osrm::util::StringView> final
|
||||
{
|
||||
std::size_t operator()(::osrm::util::StringView v) const noexcept
|
||||
{
|
||||
// Bring into scope and call un-qualified for ADL:
|
||||
// remember we want to be able to switch impl. above.
|
||||
using std::begin;
|
||||
using std::end;
|
||||
|
||||
return boost::hash_range(begin(v), end(v));
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif /* OSRM_STRING_VIEW_HPP */
|
||||
Reference in New Issue
Block a user