diff --git a/.clang-tidy b/.clang-tidy index 88a06f91b..5773ea5cd 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -61,7 +61,9 @@ Checks: '*, -readability-magic-numbers, -readability-named-parameter, -misc-no-recursion, - -concurrency-mt-unsafe' + -concurrency-mt-unsafe, + -bugprone-easily-swappable-parameters' + WarningsAsErrors: '' HeaderFilterRegex: 'src/.*' AnalyzeTemporaryDtors: false diff --git a/src/mg_import_csv.cpp b/src/mg_import_csv.cpp index 79a6bcdad..138e1e6d1 100644 --- a/src/mg_import_csv.cpp +++ b/src/mg_import_csv.cpp @@ -170,7 +170,7 @@ enum class CsvParserState { EXPECT_DELIMITER, }; -bool SubstringStartsWith(const std::string_view &str, size_t pos, const std::string_view &what) { +bool SubstringStartsWith(const std::string_view str, size_t pos, const std::string_view what) { return memgraph::utils::StartsWith(memgraph::utils::Substr(str, pos), what); } diff --git a/src/query/db_accessor.hpp b/src/query/db_accessor.hpp index 55514c883..f325e1282 100644 --- a/src/query/db_accessor.hpp +++ b/src/query/db_accessor.hpp @@ -310,11 +310,11 @@ class DbAccessor final { return std::make_optional(*value); } - storage::PropertyId NameToProperty(const std::string_view &name) { return accessor_->NameToProperty(name); } + storage::PropertyId NameToProperty(const std::string_view name) { return accessor_->NameToProperty(name); } - storage::LabelId NameToLabel(const std::string_view &name) { return accessor_->NameToLabel(name); } + storage::LabelId NameToLabel(const std::string_view name) { return accessor_->NameToLabel(name); } - storage::EdgeTypeId NameToEdgeType(const std::string_view &name) { return accessor_->NameToEdgeType(name); } + storage::EdgeTypeId NameToEdgeType(const std::string_view name) { return accessor_->NameToEdgeType(name); } const std::string &PropertyToName(storage::PropertyId prop) const { return accessor_->PropertyToName(prop); } diff --git a/src/query/dump.cpp b/src/query/dump.cpp index 88b233a54..8421e4376 100644 --- a/src/query/dump.cpp +++ b/src/query/dump.cpp @@ -46,7 +46,7 @@ const char *kInternalPropertyId = "__mg_id__"; const char *kInternalVertexLabel = "__mg_vertex__"; /// A helper function that escapes label, edge type and property names. -std::string EscapeName(const std::string_view &value) { +std::string EscapeName(const std::string_view value) { std::string out; out.reserve(value.size() + 2); out.append(1, '`'); diff --git a/src/query/interpret/eval.hpp b/src/query/interpret/eval.hpp index b5ca8ab84..fcd4557a9 100644 --- a/src/query/interpret/eval.hpp +++ b/src/query/interpret/eval.hpp @@ -716,7 +716,7 @@ class ExpressionEvaluator : public ExpressionVisitor { } template - storage::PropertyValue GetProperty(const TRecordAccessor &record_accessor, const std::string_view &name) { + storage::PropertyValue GetProperty(const TRecordAccessor &record_accessor, const std::string_view name) { auto maybe_prop = record_accessor.GetProperty(view_, dba_->NameToProperty(name)); if (maybe_prop.HasError() && maybe_prop.GetError() == storage::Error::NONEXISTENT_OBJECT) { // This is a very nasty and temporary hack in order to make MERGE work. diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 4d6660f24..74463ead0 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -3697,7 +3697,7 @@ std::unordered_map CallProcedure::GetAndResetCounters() { namespace { -void CallCustomProcedure(const std::string_view &fully_qualified_procedure_name, const mgp_proc &proc, +void CallCustomProcedure(const std::string_view fully_qualified_procedure_name, const mgp_proc &proc, const std::vector &args, mgp_graph &graph, ExpressionEvaluator *evaluator, utils::MemoryResource *memory, std::optional memory_limit, mgp_result *result) { static_assert(std::uses_allocator_v>, diff --git a/src/query/procedure/module.cpp b/src/query/procedure/module.cpp index 5c912aaf0..061308997 100644 --- a/src/query/procedure/module.cpp +++ b/src/query/procedure/module.cpp @@ -1054,7 +1054,7 @@ std::unique_ptr LoadModuleFromFile(const std::filesystem::path &path) { } // namespace -bool ModuleRegistry::RegisterModule(const std::string_view &name, std::unique_ptr module) { +bool ModuleRegistry::RegisterModule(const std::string_view name, std::unique_ptr module) { MG_ASSERT(!name.empty(), "Module name cannot be empty"); MG_ASSERT(module, "Tried to register an invalid module"); if (modules_.find(name) != modules_.end()) { @@ -1163,7 +1163,7 @@ void ModuleRegistry::UnloadAndLoadModulesFromDirectories() { } } -ModulePtr ModuleRegistry::GetModuleNamed(const std::string_view &name) const { +ModulePtr ModuleRegistry::GetModuleNamed(const std::string_view name) const { std::shared_lock guard(lock_); auto found_it = modules_.find(name); if (found_it == modules_.end()) return nullptr; diff --git a/src/query/procedure/module.hpp b/src/query/procedure/module.hpp index 17a62d738..82478257b 100644 --- a/src/query/procedure/module.hpp +++ b/src/query/procedure/module.hpp @@ -77,7 +77,7 @@ class ModuleRegistry final { mutable utils::RWLock lock_{utils::RWLock::Priority::WRITE}; std::unique_ptr shared_{std::make_unique()}; - bool RegisterModule(const std::string_view &name, std::unique_ptr module); + bool RegisterModule(std::string_view name, std::unique_ptr module); void DoUnloadAllModules(); @@ -105,7 +105,7 @@ class ModuleRegistry final { /// /// Return true if the module was loaded or reloaded successfully, false /// otherwise. - bool LoadOrReloadModuleFromName(const std::string_view name); + bool LoadOrReloadModuleFromName(std::string_view name); /// Atomically unload all modules and then load all possible modules from the /// set directories. @@ -115,7 +115,7 @@ class ModuleRegistry final { /// Find a module with given name or return nullptr. /// Takes a read lock. - ModulePtr GetModuleNamed(const std::string_view &name) const; + ModulePtr GetModuleNamed(std::string_view name) const; /// Remove all loaded (non-builtin) modules. /// Takes a write lock. @@ -175,7 +175,7 @@ extern ModuleRegistry gModuleRegistry; /// inside this function. ModulePtr must be kept alive to make sure it won't be /// unloaded. std::optional> FindProcedure( - const ModuleRegistry &module_registry, const std::string_view fully_qualified_procedure_name, + const ModuleRegistry &module_registry, std::string_view fully_qualified_procedure_name, utils::MemoryResource *memory); /// Return the ModulePtr and `mgp_trans *` of the found transformation after resolving @@ -183,7 +183,7 @@ std::optional> FindProcedure( /// inside this function. ModulePtr must be kept alive to make sure it won't be /// unloaded. std::optional> FindTransformation( - const ModuleRegistry &module_registry, const std::string_view fully_qualified_transformation_name, + const ModuleRegistry &module_registry, std::string_view fully_qualified_transformation_name, utils::MemoryResource *memory); /// Return the ModulePtr and `mgp_func *` of the found function after resolving @@ -191,7 +191,7 @@ std::optional> FindTransforma /// std::nullopt is returned. `memory` is used for temporary allocations /// inside this function. ModulePtr must be kept alive to make sure it won't be unloaded. std::optional> FindFunction( - const ModuleRegistry &module_registry, const std::string_view fully_qualified_function_name, + const ModuleRegistry &module_registry, std::string_view fully_qualified_function_name, utils::MemoryResource *memory); template diff --git a/src/query/typed_value.cpp b/src/query/typed_value.cpp index 564d40c69..1b917d297 100644 --- a/src/query/typed_value.cpp +++ b/src/query/typed_value.cpp @@ -407,7 +407,7 @@ DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(int, Int, int_v) DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(bool, Bool, bool_v) DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(int64_t, Int, int_v) DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(double, Double, double_v) -DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(const std::string_view &, String, string_v) +DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(const std::string_view, String, string_v) DEFINE_TYPED_VALUE_COPY_ASSIGNMENT(const TypedValue::TVector &, List, list_v) TypedValue &TypedValue::operator=(const std::vector &other) { diff --git a/src/query/typed_value.hpp b/src/query/typed_value.hpp index 8737eb1dc..e9d8a049e 100644 --- a/src/query/typed_value.hpp +++ b/src/query/typed_value.hpp @@ -185,7 +185,7 @@ class TypedValue { new (&string_v) TString(value, memory_); } - explicit TypedValue(const std::string_view &value, utils::MemoryResource *memory = utils::NewDeleteResource()) + explicit TypedValue(const std::string_view value, utils::MemoryResource *memory = utils::NewDeleteResource()) : memory_(memory), type_(Type::String) { new (&string_v) TString(value, memory_); } @@ -420,7 +420,7 @@ class TypedValue { TypedValue &operator=(bool); TypedValue &operator=(int64_t); TypedValue &operator=(double); - TypedValue &operator=(const std::string_view &); + TypedValue &operator=(std::string_view); TypedValue &operator=(const TVector &); TypedValue &operator=(const std::vector &); TypedValue &operator=(const TMap &); diff --git a/src/slk/serialization.hpp b/src/slk/serialization.hpp index 16a7b4fa0..f7961368f 100644 --- a/src/slk/serialization.hpp +++ b/src/slk/serialization.hpp @@ -166,7 +166,7 @@ inline void Save(const char *obj, Builder *builder) { builder->Save(reinterpret_cast(obj), size); } -inline void Save(const std::string_view &obj, Builder *builder) { +inline void Save(const std::string_view obj, Builder *builder) { uint64_t size = obj.size(); Save(size, builder); builder->Save(reinterpret_cast(obj.data()), size); diff --git a/src/storage/v2/durability/serialization.cpp b/src/storage/v2/durability/serialization.cpp index e2862d970..61c390da6 100644 --- a/src/storage/v2/durability/serialization.cpp +++ b/src/storage/v2/durability/serialization.cpp @@ -27,7 +27,7 @@ void WriteSize(Encoder *encoder, uint64_t size) { } } // namespace -void Encoder::Initialize(const std::filesystem::path &path, const std::string_view &magic, uint64_t version) { +void Encoder::Initialize(const std::filesystem::path &path, const std::string_view magic, uint64_t version) { file_.Open(path, utils::OutputFile::Mode::OVERWRITE_EXISTING); Write(reinterpret_cast(magic.data()), magic.size()); auto version_encoded = utils::HostToLittleEndian(version); @@ -73,7 +73,7 @@ void Encoder::WriteDouble(double value) { Write(reinterpret_cast(&value_uint), sizeof(value_uint)); } -void Encoder::WriteString(const std::string_view &value) { +void Encoder::WriteString(const std::string_view value) { WriteMarker(Marker::TYPE_STRING); WriteSize(this, value.size()); Write(reinterpret_cast(value.data()), value.size()); diff --git a/src/storage/v2/durability/serialization.hpp b/src/storage/v2/durability/serialization.hpp index b53f94d40..409293220 100644 --- a/src/storage/v2/durability/serialization.hpp +++ b/src/storage/v2/durability/serialization.hpp @@ -34,14 +34,14 @@ class BaseEncoder { virtual void WriteBool(bool value) = 0; virtual void WriteUint(uint64_t value) = 0; virtual void WriteDouble(double value) = 0; - virtual void WriteString(const std::string_view &value) = 0; + virtual void WriteString(std::string_view value) = 0; virtual void WritePropertyValue(const PropertyValue &value) = 0; }; /// Encoder that is used to generate a snapshot/WAL. class Encoder final : public BaseEncoder { public: - void Initialize(const std::filesystem::path &path, const std::string_view &magic, uint64_t version); + void Initialize(const std::filesystem::path &path, std::string_view magic, uint64_t version); void OpenExisting(const std::filesystem::path &path); @@ -54,7 +54,7 @@ class Encoder final : public BaseEncoder { void WriteBool(bool value) override; void WriteUint(uint64_t value) override; void WriteDouble(double value) override; - void WriteString(const std::string_view &value) override; + void WriteString(std::string_view value) override; void WritePropertyValue(const PropertyValue &value) override; uint64_t GetPosition(); diff --git a/src/storage/v2/name_id_mapper.hpp b/src/storage/v2/name_id_mapper.hpp index 946f4dd3f..4ec79cb78 100644 --- a/src/storage/v2/name_id_mapper.hpp +++ b/src/storage/v2/name_id_mapper.hpp @@ -29,8 +29,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_view &other) { return name < other; } - bool operator==(const std::string_view &other) { return name == other; } + bool operator<(const std::string_view other) const { return name < other; } + bool operator==(const std::string_view other) const { return name == other; } }; struct MapIdToName { @@ -46,7 +46,7 @@ class NameIdMapper final { public: /// @throw std::bad_alloc if unable to insert a new mapping - uint64_t NameToId(const std::string_view &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; diff --git a/src/storage/v2/replication/serialization.cpp b/src/storage/v2/replication/serialization.cpp index 059273d1a..6651b8999 100644 --- a/src/storage/v2/replication/serialization.cpp +++ b/src/storage/v2/replication/serialization.cpp @@ -30,7 +30,7 @@ void Encoder::WriteDouble(double value) { slk::Save(value, builder_); } -void Encoder::WriteString(const std::string_view &value) { +void Encoder::WriteString(const std::string_view value) { WriteMarker(durability::Marker::TYPE_STRING); slk::Save(value, builder_); } diff --git a/src/storage/v2/replication/serialization.hpp b/src/storage/v2/replication/serialization.hpp index 36d228e3c..738f55ea4 100644 --- a/src/storage/v2/replication/serialization.hpp +++ b/src/storage/v2/replication/serialization.hpp @@ -33,7 +33,7 @@ class Encoder final : public durability::BaseEncoder { void WriteDouble(double value) override; - void WriteString(const std::string_view &value) override; + void WriteString(std::string_view value) override; void WritePropertyValue(const PropertyValue &value) override; diff --git a/src/storage/v2/storage.cpp b/src/storage/v2/storage.cpp index 5ad55bc75..471a346c4 100644 --- a/src/storage/v2/storage.cpp +++ b/src/storage/v2/storage.cpp @@ -812,11 +812,11 @@ const std::string &Storage::Accessor::EdgeTypeToName(EdgeTypeId edge_type) const return storage_->EdgeTypeToName(edge_type); } -LabelId Storage::Accessor::NameToLabel(const std::string_view &name) { return storage_->NameToLabel(name); } +LabelId Storage::Accessor::NameToLabel(const std::string_view name) { return storage_->NameToLabel(name); } -PropertyId Storage::Accessor::NameToProperty(const std::string_view &name) { return storage_->NameToProperty(name); } +PropertyId Storage::Accessor::NameToProperty(const std::string_view name) { return storage_->NameToProperty(name); } -EdgeTypeId Storage::Accessor::NameToEdgeType(const std::string_view &name) { return storage_->NameToEdgeType(name); } +EdgeTypeId Storage::Accessor::NameToEdgeType(const std::string_view name) { return storage_->NameToEdgeType(name); } void Storage::Accessor::AdvanceCommand() { ++transaction_.command_id; } @@ -1121,13 +1121,13 @@ const std::string &Storage::EdgeTypeToName(EdgeTypeId edge_type) const { return name_id_mapper_.IdToName(edge_type.AsUint()); } -LabelId Storage::NameToLabel(const std::string_view &name) { return LabelId::FromUint(name_id_mapper_.NameToId(name)); } +LabelId Storage::NameToLabel(const std::string_view name) { return LabelId::FromUint(name_id_mapper_.NameToId(name)); } -PropertyId Storage::NameToProperty(const std::string_view &name) { +PropertyId Storage::NameToProperty(const std::string_view name) { return PropertyId::FromUint(name_id_mapper_.NameToId(name)); } -EdgeTypeId Storage::NameToEdgeType(const std::string_view &name) { +EdgeTypeId Storage::NameToEdgeType(const std::string_view name) { return EdgeTypeId::FromUint(name_id_mapper_.NameToId(name)); } diff --git a/src/storage/v2/storage.hpp b/src/storage/v2/storage.hpp index cbff984fd..50e2e982b 100644 --- a/src/storage/v2/storage.hpp +++ b/src/storage/v2/storage.hpp @@ -283,13 +283,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_view &name); + LabelId NameToLabel(std::string_view name); /// @throw std::bad_alloc if unable to insert a new mapping - PropertyId NameToProperty(const std::string_view &name); + PropertyId NameToProperty(std::string_view name); /// @throw std::bad_alloc if unable to insert a new mapping - EdgeTypeId NameToEdgeType(const std::string_view &name); + EdgeTypeId NameToEdgeType(std::string_view name); bool LabelIndexExists(LabelId label) const { return storage_->indices_.label_index.IndexExists(label); } @@ -343,13 +343,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_view &name); + LabelId NameToLabel(std::string_view name); /// @throw std::bad_alloc if unable to insert a new mapping - PropertyId NameToProperty(const std::string_view &name); + PropertyId NameToProperty(std::string_view name); /// @throw std::bad_alloc if unable to insert a new mapping - EdgeTypeId NameToEdgeType(const std::string_view &name); + EdgeTypeId NameToEdgeType(std::string_view name); /// @throw std::bad_alloc bool CreateIndex(LabelId label, std::optional desired_commit_timestamp = {}); diff --git a/src/utils/file.cpp b/src/utils/file.cpp index d7fe100c5..96fa0763e 100644 --- a/src/utils/file.cpp +++ b/src/utils/file.cpp @@ -370,7 +370,7 @@ void OutputFile::Write(const uint8_t *data, size_t size) { } void OutputFile::Write(const char *data, size_t size) { Write(reinterpret_cast(data), size); } -void OutputFile::Write(const std::string_view &data) { Write(data.data(), data.size()); } +void OutputFile::Write(const std::string_view data) { Write(data.data(), data.size()); } size_t OutputFile::SeekFile(const Position position, const ssize_t offset) { int whence; diff --git a/src/utils/file.hpp b/src/utils/file.hpp index c98e6dd4d..5e1345742 100644 --- a/src/utils/file.hpp +++ b/src/utils/file.hpp @@ -209,7 +209,7 @@ class OutputFile { /// the program. void Write(const uint8_t *data, size_t size); void Write(const char *data, size_t size); - void Write(const std::string_view &data); + void Write(std::string_view data); /// This method gets the current absolute position in the file. On failure and /// misuse it crashes the program. diff --git a/src/utils/fnv.hpp b/src/utils/fnv.hpp index 3a5682cc8..08db28d91 100644 --- a/src/utils/fnv.hpp +++ b/src/utils/fnv.hpp @@ -16,7 +16,7 @@ namespace memgraph::utils { -inline uint64_t Fnv(const std::string_view &s) { +inline uint64_t Fnv(const std::string_view s) { // fnv1a is recommended so use it as the default implementation. uint64_t hash = 14695981039346656037UL; diff --git a/src/utils/string.hpp b/src/utils/string.hpp index 9f6eddf6b..e19623822 100644 --- a/src/utils/string.hpp +++ b/src/utils/string.hpp @@ -29,7 +29,7 @@ namespace memgraph::utils { /** Remove whitespace characters from the start of a string. */ -inline std::string_view LTrim(const std::string_view &s) { +inline std::string_view LTrim(const std::string_view s) { size_t start = 0; while (start < s.size() && isspace(s[start])) { ++start; @@ -38,7 +38,7 @@ inline std::string_view LTrim(const std::string_view &s) { } /** Remove characters found in `chars` from the start of a string. */ -inline std::string_view LTrim(const std::string_view &s, const std::string_view &chars) { +inline std::string_view LTrim(const std::string_view s, const std::string_view chars) { size_t start = 0; while (start < s.size() && chars.find(s[start]) != std::string::npos) { ++start; @@ -47,7 +47,7 @@ inline std::string_view LTrim(const std::string_view &s, const std::string_view } /** Remove whitespace characters from the end of a string. */ -inline std::string_view RTrim(const std::string_view &s) { +inline std::string_view RTrim(const std::string_view s) { size_t count = s.size(); while (count > static_cast(0) && isspace(s[count - 1])) { --count; @@ -56,7 +56,7 @@ inline std::string_view RTrim(const std::string_view &s) { } /** Remove characters found in `chars` from the end of a string. */ -inline std::string_view RTrim(const std::string_view &s, const std::string_view &chars) { +inline std::string_view RTrim(const std::string_view s, const std::string_view chars) { size_t count = s.size(); while (count > static_cast(0) && chars.find(s[count - 1]) != std::string::npos) { --count; @@ -65,7 +65,7 @@ inline std::string_view RTrim(const std::string_view &s, const std::string_view } /** Remove whitespace characters from the start and from the end of a string. */ -inline std::string_view Trim(const std::string_view &s) { +inline std::string_view Trim(const std::string_view s) { size_t start = 0; size_t count = s.size(); while (start < s.size() && isspace(s[start])) { @@ -78,7 +78,7 @@ inline std::string_view Trim(const std::string_view &s) { } /** Remove characters found in `chars` from the start and the end of `s`. */ -inline std::string_view Trim(const std::string_view &s, const std::string_view &chars) { +inline std::string_view Trim(const std::string_view s, const std::string_view chars) { size_t start = 0; size_t count = s.size(); while (start < s.size() && chars.find(s[start]) != std::string::npos) { @@ -97,7 +97,7 @@ inline std::string_view Trim(const std::string_view &s, const std::string_view & */ template std::basic_string, TAllocator> *ToLowerCase( - std::basic_string, TAllocator> *out, const std::string_view &s) { + std::basic_string, TAllocator> *out, const std::string_view s) { out->resize(s.size()); std::transform(s.begin(), s.end(), out->begin(), [](char c) { return tolower(c); }); return out; @@ -107,7 +107,7 @@ std::basic_string, TAllocator> *ToLowerCase( * Lowercase all characters of a string. * Transformation is locale independent. */ -inline std::string ToLowerCase(const std::string_view &s) { +inline std::string ToLowerCase(const std::string_view s) { std::string res; ToLowerCase(&res, s); return res; @@ -120,7 +120,7 @@ inline std::string ToLowerCase(const std::string_view &s) { */ template std::basic_string, TAllocator> *ToUpperCase( - std::basic_string, TAllocator> *out, const std::string_view &s) { + std::basic_string, TAllocator> *out, const std::string_view s) { out->resize(s.size()); std::transform(s.begin(), s.end(), out->begin(), [](char c) { return toupper(c); }); return out; @@ -130,7 +130,7 @@ std::basic_string, TAllocator> *ToUpperCase( * Uppercase all characters of a string and store the result in `out`. * Transformation is locale independent. */ -inline std::string ToUpperCase(const std::string_view &s) { +inline std::string ToUpperCase(const std::string_view s) { std::string res; ToUpperCase(&res, s); return res; @@ -143,7 +143,7 @@ inline std::string ToUpperCase(const std::string_view &s) { template std::basic_string, TAllocator> *Join( std::basic_string, TAllocator> *out, const TCollection &strings, - const std::string_view &separator) { + const std::string_view separator) { out->clear(); if (strings.empty()) return out; int64_t total_size = 0; @@ -163,7 +163,7 @@ std::basic_string, TAllocator> *Join( /** * Join the `strings` collection separated by a given separator. */ -inline std::string Join(const std::vector &strings, const std::string_view &separator) { +inline std::string Join(const std::vector &strings, const std::string_view separator) { std::string res; Join(&res, strings, separator); return res; @@ -175,8 +175,8 @@ inline std::string Join(const std::vector &strings, const std::stri */ template std::basic_string, TAllocator> *Replace( - std::basic_string, TAllocator> *out, const std::string_view &src, - const std::string_view &match, const std::string_view &replacement) { + std::basic_string, TAllocator> *out, const std::string_view src, + const std::string_view match, const std::string_view replacement) { // TODO: This could be implemented much more efficiently. *out = src; for (size_t pos = out->find(match); pos != std::string::npos; pos = out->find(match, pos + replacement.size())) { @@ -186,8 +186,8 @@ std::basic_string, TAllocator> *Replace( } /** Replace all occurrences of `match` in `src` with `replacement`. */ -inline std::string Replace(const std::string_view &src, const std::string_view &match, - const std::string_view &replacement) { +inline std::string Replace(const std::string_view src, const std::string_view match, + const std::string_view replacement) { std::string res; Replace(&res, src, match, replacement); return res; @@ -200,8 +200,8 @@ inline std::string Replace(const std::string_view &src, const std::string_view & * @return pointer to `out`. */ template -std::vector *Split(std::vector *out, const std::string_view &src, - const std::string_view &delimiter, int splits = -1) { +std::vector *Split(std::vector *out, const std::string_view src, + const std::string_view delimiter, int splits = -1) { out->clear(); if (src.empty()) return out; size_t index = 0; @@ -220,7 +220,7 @@ std::vector *Split(std::vector *out, c * The vector will have at most `splits` + 1 elements. Negative value of * `splits` indicates to perform all possible splits. */ -inline std::vector Split(const std::string_view &src, const std::string_view &delimiter, int splits = -1) { +inline std::vector Split(const std::string_view src, const std::string_view delimiter, int splits = -1) { std::vector res; Split(&res, src, delimiter, splits); return res; @@ -234,7 +234,7 @@ inline std::vector Split(const std::string_view &src, const std::st * @return pointer to `out`. */ template -std::vector *Split(std::vector *out, const std::string_view &src) { +std::vector *Split(std::vector *out, const std::string_view src) { out->clear(); if (src.empty()) return out; // TODO: Investigate how much regex allocate and perhaps replace with custom @@ -256,7 +256,7 @@ std::vector *Split(std::vector *out, c * Additionally, the result will not contain empty strings at the start or end * as if the string was trimmed before splitting. */ -inline std::vector Split(const std::string_view &src) { +inline std::vector Split(const std::string_view src) { std::vector res; Split(&res, src); return res; @@ -271,8 +271,8 @@ inline std::vector Split(const std::string_view &src) { * @return pointer to `out`. */ template -std::vector *RSplit(std::vector *out, const std::string_view &src, - const std::string_view &delimiter, int splits = -1) { +std::vector *RSplit(std::vector *out, const std::string_view src, + const std::string_view delimiter, int splits = -1) { out->clear(); if (src.empty()) return out; size_t index = src.size(); @@ -295,8 +295,7 @@ std::vector *RSplit(std::vector *out, * have at most `splits` + 1 elements. Negative value of `splits` indicates to * perform all possible splits. */ -inline std::vector RSplit(const std::string_view &src, const std::string_view &delimiter, - int splits = -1) { +inline std::vector RSplit(const std::string_view src, const std::string_view delimiter, int splits = -1) { std::vector res; RSplit(&res, src, delimiter, splits); return res; @@ -309,7 +308,7 @@ inline std::vector RSplit(const std::string_view &src, const std::s * * @throw BasicException if unable to parse the whole string. */ -inline int64_t ParseInt(const std::string_view &s) { +inline int64_t ParseInt(const std::string_view s) { // stol would be nicer but it uses current locale so we shouldn't use it. int64_t t = 0; // NOTE: Constructing std::istringstream will make a copy of the string, which @@ -336,7 +335,7 @@ inline int64_t ParseInt(const std::string_view &s) { * * @throw BasicException if unable to parse the whole string. */ -inline double ParseDouble(const std::string_view &s) { +inline double ParseDouble(const std::string_view s) { // stod would be nicer but it uses current locale so we shouldn't use it. double t = 0.0; // NOTE: Constructing std::istringstream will make a copy of the string, which @@ -357,17 +356,17 @@ inline double ParseDouble(const std::string_view &s) { } /** Check if the given string `s` ends with the given `suffix`. */ -inline bool EndsWith(const std::string_view &s, const std::string_view &suffix) { +inline bool EndsWith(const std::string_view s, const std::string_view suffix) { return s.size() >= suffix.size() && s.compare(s.size() - suffix.size(), std::string::npos, suffix) == 0; } /** Check if the given string `s` starts with the given `prefix`. */ -inline bool StartsWith(const std::string_view &s, const std::string_view &prefix) { +inline bool StartsWith(const std::string_view s, const std::string_view prefix) { return s.size() >= prefix.size() && s.compare(0, prefix.size(), prefix) == 0; } /** Perform case-insensitive string equality test. */ -inline bool IEquals(const std::string_view &lhs, const std::string_view &rhs) { +inline bool IEquals(const std::string_view lhs, const std::string_view rhs) { if (lhs.size() != rhs.size()) return false; for (size_t i = 0; i < lhs.size(); ++i) { if (tolower(lhs[i]) != tolower(rhs[i])) return false; @@ -406,7 +405,7 @@ inline std::string RandomString(size_t length) { */ template std::basic_string, TAllocator> *Escape( - std::basic_string, TAllocator> *out, const std::string_view &src) { + std::basic_string, TAllocator> *out, const std::string_view src) { out->clear(); out->reserve(src.size() + 2); out->append(1, '"'); @@ -433,7 +432,7 @@ std::basic_string, TAllocator> *Escape( } /** Escape all whitespace and quotation characters in the given string. */ -inline std::string Escape(const std::string_view &src) { +inline std::string Escape(const std::string_view src) { std::string res; Escape(&res, src); return res; @@ -445,7 +444,7 @@ inline std::string Escape(const std::string_view &src) { * clamped to a valid interval. Therefore, this function never throws * std::out_of_range, unlike std::basic_string::substr. */ -inline std::string_view Substr(const std::string_view &string, size_t pos = 0, size_t count = std::string::npos) { +inline std::string_view Substr(const std::string_view string, size_t pos = 0, size_t count = std::string::npos) { if (pos >= string.size()) return std::string_view(string.data(), 0); auto len = std::min(string.size() - pos, count); return string.substr(pos, len); diff --git a/tests/unit/cypher_main_visitor.cpp b/tests/unit/cypher_main_visitor.cpp index 814f3fa7c..39663e2ea 100644 --- a/tests/unit/cypher_main_visitor.cpp +++ b/tests/unit/cypher_main_visitor.cpp @@ -3044,7 +3044,7 @@ void CheckParsedCallProcedure(const CypherQuery &query, Base &ast_generator, } std::vector args_as_str{}; std::transform(args.begin(), args.end(), std::back_inserter(args_as_str), - [](const std::string_view &arg) { return std::string{arg}; }); + [](const std::string_view arg) { return std::string{arg}; }); EXPECT_EQ(identifier_names, args_as_str); EXPECT_EQ(identifier_names, call_proc->result_fields_); ASSERT_EQ(call_proc->is_write_, type == ProcedureType::WRITE);