From ef7903a90f55c8d2ca233b71bd11892a724fba3e Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Tue, 3 Sep 2019 11:19:49 +0200 Subject: [PATCH] alternator: migrate make_map_element_restriction to string view In order to elide unnecessary copying and allow more copy elision in the future, make_map_element_restriction helper function uses string_view instead of a const string reference. Message-Id: <1a3e82e7046dc40df604ee7fbea786f3853fee4d.1567502264.git.sarna@scylladb.com> --- alternator/conditions.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/alternator/conditions.cc b/alternator/conditions.cc index f60addc7ce..958c43e541 100644 --- a/alternator/conditions.cc +++ b/alternator/conditions.cc @@ -21,6 +21,7 @@ #include #include +#include #include "alternator/conditions.hh" #include "alternator/error.hh" #include "cql3/constants.hh" @@ -52,8 +53,8 @@ comparison_operator_type get_comparison_operator(const rjson::value& comparison_ return it->second; } -static ::shared_ptr make_map_element_restriction(const column_definition& cdef, const std::string& key, const rjson::value& value) { - bytes raw_key = utf8_type->from_string(sstring(key)); +static ::shared_ptr make_map_element_restriction(const column_definition& cdef, std::string_view key, const rjson::value& value) { + bytes raw_key = utf8_type->from_string(sstring_view(key.data(), key.size())); auto key_value = ::make_shared(cql3::raw_value::make_value(std::move(raw_key))); bytes raw_value = serialize_item(value); auto entry_value = ::make_shared(cql3::raw_value::make_value(std::move(raw_value))); @@ -70,7 +71,7 @@ static ::shared_ptr make_key_ clogger.trace("Getting filtering restrictions for: {}", rjson::print(query_filter)); auto filtering_restrictions = ::make_shared(schema, true); for (auto it = query_filter.MemberBegin(); it != query_filter.MemberEnd(); ++it) { - std::string column_name = it->name.GetString(); + std::string_view column_name(it->name.GetString(), it->name.GetStringLength()); const rjson::value& condition = it->value; const rjson::value& comp_definition = rjson::get(condition, "ComparisonOperator"); @@ -83,7 +84,7 @@ static ::shared_ptr make_key_ if (attr_list.Size() != 1) { throw api_error("ValidationException", format("EQ restriction needs exactly 1 attribute value: {}", rjson::print(attr_list))); } - if (const column_definition* cdef = schema->get_column_definition(to_bytes(column_name))) { + if (const column_definition* cdef = schema->get_column_definition(to_bytes(column_name.data()))) { // Primary key restriction filtering_restrictions->add_restriction(make_key_eq_restriction(*cdef, attr_list[0]), false, true); } else {