Use std::string_view
in storage NameTo...
functions
Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2683
This commit is contained in:
parent
e7f363ecbe
commit
2562070b06
src
@ -275,17 +275,15 @@ class DbAccessor final {
|
||||
}
|
||||
|
||||
storage::PropertyId NameToProperty(const std::string_view &name) {
|
||||
// TODO: New storage should work with string_view to avoid needless
|
||||
// allocation.
|
||||
return accessor_->NameToProperty(std::string(name));
|
||||
return accessor_->NameToProperty(name);
|
||||
}
|
||||
|
||||
storage::LabelId NameToLabel(const std::string_view &name) {
|
||||
return accessor_->NameToLabel(std::string(name));
|
||||
return accessor_->NameToLabel(name);
|
||||
}
|
||||
|
||||
storage::EdgeTypeId NameToEdgeType(const std::string_view &name) {
|
||||
return accessor_->NameToEdgeType(std::string(name));
|
||||
return accessor_->NameToEdgeType(name);
|
||||
}
|
||||
|
||||
const std::string &PropertyToName(storage::PropertyId prop) const {
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "utils/skip_list.hpp"
|
||||
|
||||
@ -16,8 +17,8 @@ class NameIdMapper final {
|
||||
bool operator<(const MapNameToId &other) { return name < other.name; }
|
||||
bool operator==(const MapNameToId &other) { return name == other.name; }
|
||||
|
||||
bool operator<(const std::string &other) { return name < other; }
|
||||
bool operator==(const std::string &other) { return name == other; }
|
||||
bool operator<(const std::string_view &other) { return name < other; }
|
||||
bool operator==(const std::string_view &other) { return name == other; }
|
||||
};
|
||||
|
||||
struct MapIdToName {
|
||||
@ -33,7 +34,7 @@ class NameIdMapper final {
|
||||
|
||||
public:
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
uint64_t NameToId(const std::string &name) {
|
||||
uint64_t NameToId(const std::string_view &name) {
|
||||
auto name_to_id_acc = name_to_id_.access();
|
||||
auto found = name_to_id_acc.find(name);
|
||||
uint64_t id;
|
||||
@ -45,7 +46,7 @@ class NameIdMapper final {
|
||||
// return an iterator to the existing item. This prevents assignment of
|
||||
// two IDs to the same name when the mapping is being inserted
|
||||
// concurrently from two threads. One ID is wasted in that case, though.
|
||||
id = name_to_id_acc.insert({name, new_id}).first->id;
|
||||
id = name_to_id_acc.insert({std::string(name), new_id}).first->id;
|
||||
} else {
|
||||
id = found->id;
|
||||
}
|
||||
@ -56,7 +57,7 @@ class NameIdMapper final {
|
||||
if (id_to_name_acc.find(id) == id_to_name_acc.end()) {
|
||||
// We first try to find the `id` in the map to avoid making an unnecessary
|
||||
// temporary memory allocation when the object already exists.
|
||||
id_to_name_acc.insert({id, name});
|
||||
id_to_name_acc.insert({id, std::string(name)});
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
@ -625,15 +625,15 @@ const std::string &Storage::Accessor::EdgeTypeToName(
|
||||
return storage_->EdgeTypeToName(edge_type);
|
||||
}
|
||||
|
||||
LabelId Storage::Accessor::NameToLabel(const std::string &name) {
|
||||
LabelId Storage::Accessor::NameToLabel(const std::string_view &name) {
|
||||
return storage_->NameToLabel(name);
|
||||
}
|
||||
|
||||
PropertyId Storage::Accessor::NameToProperty(const std::string &name) {
|
||||
PropertyId Storage::Accessor::NameToProperty(const std::string_view &name) {
|
||||
return storage_->NameToProperty(name);
|
||||
}
|
||||
|
||||
EdgeTypeId Storage::Accessor::NameToEdgeType(const std::string &name) {
|
||||
EdgeTypeId Storage::Accessor::NameToEdgeType(const std::string_view &name) {
|
||||
return storage_->NameToEdgeType(name);
|
||||
}
|
||||
|
||||
@ -966,15 +966,15 @@ const std::string &Storage::EdgeTypeToName(EdgeTypeId edge_type) const {
|
||||
return name_id_mapper_.IdToName(edge_type.AsUint());
|
||||
}
|
||||
|
||||
LabelId Storage::NameToLabel(const std::string &name) {
|
||||
LabelId Storage::NameToLabel(const std::string_view &name) {
|
||||
return LabelId::FromUint(name_id_mapper_.NameToId(name));
|
||||
}
|
||||
|
||||
PropertyId Storage::NameToProperty(const std::string &name) {
|
||||
PropertyId Storage::NameToProperty(const std::string_view &name) {
|
||||
return PropertyId::FromUint(name_id_mapper_.NameToId(name));
|
||||
}
|
||||
|
||||
EdgeTypeId Storage::NameToEdgeType(const std::string &name) {
|
||||
EdgeTypeId Storage::NameToEdgeType(const std::string_view &name) {
|
||||
return EdgeTypeId::FromUint(name_id_mapper_.NameToId(name));
|
||||
}
|
||||
|
||||
|
@ -265,13 +265,13 @@ class Storage final {
|
||||
const std::string &EdgeTypeToName(EdgeTypeId edge_type) const;
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
LabelId NameToLabel(const std::string &name);
|
||||
LabelId NameToLabel(const std::string_view &name);
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
PropertyId NameToProperty(const std::string &name);
|
||||
PropertyId NameToProperty(const std::string_view &name);
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
EdgeTypeId NameToEdgeType(const std::string &name);
|
||||
EdgeTypeId NameToEdgeType(const std::string_view &name);
|
||||
|
||||
bool LabelIndexExists(LabelId label) const {
|
||||
return storage_->indices_.label_index.IndexExists(label);
|
||||
@ -318,13 +318,13 @@ class Storage final {
|
||||
const std::string &EdgeTypeToName(EdgeTypeId edge_type) const;
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
LabelId NameToLabel(const std::string &name);
|
||||
LabelId NameToLabel(const std::string_view &name);
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
PropertyId NameToProperty(const std::string &name);
|
||||
PropertyId NameToProperty(const std::string_view &name);
|
||||
|
||||
/// @throw std::bad_alloc if unable to insert a new mapping
|
||||
EdgeTypeId NameToEdgeType(const std::string &name);
|
||||
EdgeTypeId NameToEdgeType(const std::string_view &name);
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
bool CreateIndex(LabelId label);
|
||||
|
Loading…
Reference in New Issue
Block a user