diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2021-03-15 22:56:51 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-19 05:54:14 +0000 |
commit | b0e48211b3cbda845bd18c3283fe0d5f5dcd98c6 (patch) | |
tree | da67a68169b9c3b73c7a97b6af0f2c3321281bf7 /src | |
parent | 612a3725d98381bf9c0777bcd6b2169cae33f4d1 (diff) | |
download | mongo-b0e48211b3cbda845bd18c3283fe0d5f5dcd98c6.tar.gz |
SERVER-55180 Convert SBE from std::string_view to StringData
Remove implicit StringData <=> string_view conversions
Diffstat (limited to 'src')
34 files changed, 207 insertions, 269 deletions
diff --git a/src/mongo/base/string_data.h b/src/mongo/base/string_data.h index bc2ee4ffc36..eb762771a77 100644 --- a/src/mongo/base/string_data.h +++ b/src/mongo/base/string_data.h @@ -90,12 +90,6 @@ public: StringData(const std::string& s) : StringData(s.data(), s.length(), TrustedInitTag()) {} /** - * Implicitly convert a std::string_view to a StringData. We can use the trusted - * init path because string_view::data() points to length() bytes of data. - */ - StringData(std::string_view s) : StringData(s.data(), s.length(), TrustedInitTag()) {} - - /** * Constructs a StringData with an explicit length. 'c' must * either be nullptr (in which case len must be zero), or be a * pointer into a character array. The StringData will refer to @@ -112,18 +106,6 @@ public: } /** - * Implicitly convert to a std::string_view. - */ - operator std::string_view() const { - // std::string_view produces undefined behaviour if [pointer, pointer + size) is not a valid - // range. To fix this we explicitly use default constructor if StringData contains nullptr. - if (MONGO_unlikely(rawData() == nullptr)) { - return {}; - } - return {rawData(), size()}; - } - - /** * Constructs a StringData with begin and end iterators. begin points to the beginning of the * string. end points to the position past the end of the string. In a null-terminated string, * end points to the null-terminator. diff --git a/src/mongo/db/exec/sbe/expressions/expression.h b/src/mongo/db/exec/sbe/expressions/expression.h index 4e811337cc3..f52acef32ca 100644 --- a/src/mongo/db/exec/sbe/expressions/expression.h +++ b/src/mongo/db/exec/sbe/expressions/expression.h @@ -317,7 +317,7 @@ auto makeSV(Args&&... args) { class EConstant final : public EExpression { public: EConstant(value::TypeTags tag, value::Value val) : _tag(tag), _val(val) {} - EConstant(std::string_view str) { + EConstant(StringData str) { // Views are non-owning so we have to make a copy. std::tie(_tag, _val) = value::makeNewString(str); } @@ -448,7 +448,7 @@ private: */ class EFunction final : public EExpression { public: - EFunction(std::string_view name, std::vector<std::unique_ptr<EExpression>> args) : _name(name) { + EFunction(StringData name, std::vector<std::unique_ptr<EExpression>> args) : _name(name) { _nodes = std::move(args); validateNodes(); } @@ -513,7 +513,7 @@ private: */ class EFail final : public EExpression { public: - EFail(ErrorCodes::Error code, std::string_view message) : _code(code) { + EFail(ErrorCodes::Error code, StringData message) : _code(code) { std::tie(_messageTag, _messageVal) = value::makeNewString(message); } diff --git a/src/mongo/db/exec/sbe/expressions/sbe_concat_test.cpp b/src/mongo/db/exec/sbe/expressions/sbe_concat_test.cpp index 857704fb5b5..4275ae03eee 100644 --- a/src/mongo/db/exec/sbe/expressions/sbe_concat_test.cpp +++ b/src/mongo/db/exec/sbe/expressions/sbe_concat_test.cpp @@ -33,8 +33,7 @@ namespace mongo::sbe { class SBEConcatTest : public EExpressionTestFixture { protected: - void runAndAssertExpression(const vm::CodeFragment* compiledExpr, - std::string_view expectedVal) { + void runAndAssertExpression(const vm::CodeFragment* compiledExpr, StringData expectedVal) { auto [tag, val] = runCompiledExpression(compiledExpr); value::ValueGuard guard(tag, val); diff --git a/src/mongo/db/exec/sbe/expressions/sbe_regex_test.cpp b/src/mongo/db/exec/sbe/expressions/sbe_regex_test.cpp index 2e3c87789cb..8486a7c65f8 100644 --- a/src/mongo/db/exec/sbe/expressions/sbe_regex_test.cpp +++ b/src/mongo/db/exec/sbe/expressions/sbe_regex_test.cpp @@ -32,8 +32,7 @@ namespace mongo::sbe { class SBERegexTest : public EExpressionTestFixture { protected: - void runAndAssertRegexCompile(const vm::CodeFragment* compiledExpr, - std::string_view regexString) { + void runAndAssertRegexCompile(const vm::CodeFragment* compiledExpr, StringData regexString) { auto [tag, val] = runCompiledExpression(compiledExpr); value::ValueGuard guard(tag, val); @@ -53,7 +52,7 @@ protected: } void runAndAssertFindExpression(const vm::CodeFragment* compiledExpr, - std::string_view expectedMatch, + StringData expectedMatch, int idx) { auto [tag, val] = runCompiledExpression(compiledExpr); value::ValueGuard guard(tag, val); @@ -72,7 +71,7 @@ protected: ASSERT_EQUALS(value::numericCast<int32_t>(idxTag, idxVal), idx); } - void addMatchResult(value::Array* arrayPtr, std::string_view matchStr, int32_t idx) { + void addMatchResult(value::Array* arrayPtr, StringData matchStr, int32_t idx) { auto [objTag, objVal] = value::makeNewObject(); value::ValueGuard objGuard{objTag, objVal}; auto obj = value::getObjectView(objVal); diff --git a/src/mongo/db/exec/sbe/parser/parser.cpp b/src/mongo/db/exec/sbe/parser/parser.cpp index 19fe41378ef..a426b9d9a8d 100644 --- a/src/mongo/db/exec/sbe/parser/parser.cpp +++ b/src/mongo/db/exec/sbe/parser/parser.cpp @@ -1161,7 +1161,7 @@ std::unique_ptr<PlanStage> Parser::walkPathValue(AstQuery& ast, std::move(inputStage), getCurrentPlanNodeId(), outputSlot, - makeE<EFunction>("getField"sv, + makeE<EFunction>("getField"_sd, makeEs(makeE<EVariable>(inputSlot), makeE<EConstant>(ast.nodes[0]->identifier)))); } @@ -1172,7 +1172,7 @@ std::unique_ptr<PlanStage> Parser::walkPathValue(AstQuery& ast, makeProjectStage(std::move(inputStage), getCurrentPlanNodeId(), traverseIn, - makeE<EFunction>("getField"sv, + makeE<EFunction>("getField"_sd, makeEs(makeE<EVariable>(inputSlot), makeE<EConstant>(ast.nodes[0]->identifier)))); auto in = makeS<LimitSkipStage>( diff --git a/src/mongo/db/exec/sbe/sbe_filter_test.cpp b/src/mongo/db/exec/sbe/sbe_filter_test.cpp index eb7c7c05214..15a34975c9f 100644 --- a/src/mongo/db/exec/sbe/sbe_filter_test.cpp +++ b/src/mongo/db/exec/sbe/sbe_filter_test.cpp @@ -33,7 +33,6 @@ #include "mongo/platform/basic.h" -#include <string_view> #include "mongo/db/exec/sbe/sbe_plan_stage_test.h" #include "mongo/db/exec/sbe/stages/filter.h" @@ -148,7 +147,7 @@ TEST_F(FilterStageTest, FilterIsNumberTest) { // Build a FilterStage whose filter expression is "isNumber(scanSlot)". auto filter = makeS<FilterStage<false>>( std::move(scanStage), - makeE<EFunction>("isNumber"sv, makeEs(makeE<EVariable>(scanSlot))), + makeE<EFunction>("isNumber"_sd, makeEs(makeE<EVariable>(scanSlot))), kEmptyPlanNodeId); return std::make_pair(scanSlot, std::move(filter)); diff --git a/src/mongo/db/exec/sbe/sbe_hash_agg_test.cpp b/src/mongo/db/exec/sbe/sbe_hash_agg_test.cpp index 281a7cf0684..2c3bd3d335d 100644 --- a/src/mongo/db/exec/sbe/sbe_hash_agg_test.cpp +++ b/src/mongo/db/exec/sbe/sbe_hash_agg_test.cpp @@ -33,7 +33,6 @@ #include "mongo/platform/basic.h" -#include <string_view> #include "mongo/db/exec/sbe/sbe_plan_stage_test.h" #include "mongo/db/exec/sbe/stages/hash_agg.h" @@ -115,7 +114,7 @@ TEST_F(HashAggStageTest, HashAggAddToSetTest) { auto [expectedTag, expectedVal] = value::makeNewArray(); value::ValueGuard expectedGuard{expectedTag, expectedVal}; - for (auto&& sv : std::array<std::string_view, 4>{"Aa", "BB", "cc", "dD"}) { + for (auto&& sv : std::array<StringData, 4>{"Aa", "BB", "cc", "dD"}) { auto [tag, val] = value::makeNewString(sv); value::getArrayView(expectedVal)->push_back(tag, val); } diff --git a/src/mongo/db/exec/sbe/sbe_hash_join_test.cpp b/src/mongo/db/exec/sbe/sbe_hash_join_test.cpp index 956831cc8e0..fc9b18a2fdc 100644 --- a/src/mongo/db/exec/sbe/sbe_hash_join_test.cpp +++ b/src/mongo/db/exec/sbe/sbe_hash_join_test.cpp @@ -33,7 +33,6 @@ #include "mongo/platform/basic.h" -#include <string_view> #include "mongo/db/exec/sbe/sbe_plan_stage_test.h" #include "mongo/db/exec/sbe/stages/hash_join.h" diff --git a/src/mongo/db/exec/sbe/sbe_plan_stage_test.cpp b/src/mongo/db/exec/sbe/sbe_plan_stage_test.cpp index 473ffbe5510..0782f0bdc42 100644 --- a/src/mongo/db/exec/sbe/sbe_plan_stage_test.cpp +++ b/src/mongo/db/exec/sbe/sbe_plan_stage_test.cpp @@ -36,7 +36,6 @@ #include "mongo/db/exec/sbe/sbe_plan_stage_test.h" -#include <string_view> #include "mongo/logv2/log.h" diff --git a/src/mongo/db/exec/sbe/sbe_sort_test.cpp b/src/mongo/db/exec/sbe/sbe_sort_test.cpp index 1d4574f2d50..83b59daa535 100644 --- a/src/mongo/db/exec/sbe/sbe_sort_test.cpp +++ b/src/mongo/db/exec/sbe/sbe_sort_test.cpp @@ -29,7 +29,6 @@ #include "mongo/platform/basic.h" -#include <string_view> #include "mongo/db/exec/sbe/sbe_plan_stage_test.h" #include "mongo/db/exec/sbe/stages/sort.h" diff --git a/src/mongo/db/exec/sbe/sbe_sorted_merge_test.cpp b/src/mongo/db/exec/sbe/sbe_sorted_merge_test.cpp index 37cad8d4532..009106f8c59 100644 --- a/src/mongo/db/exec/sbe/sbe_sorted_merge_test.cpp +++ b/src/mongo/db/exec/sbe/sbe_sorted_merge_test.cpp @@ -29,7 +29,6 @@ #include "mongo/platform/basic.h" -#include <string_view> #include "mongo/db/exec/sbe/sbe_plan_stage_test.h" #include "mongo/db/exec/sbe/stages/sorted_merge.h" diff --git a/src/mongo/db/exec/sbe/sbe_test.cpp b/src/mongo/db/exec/sbe/sbe_test.cpp index 74460db8e2c..ad7529e96bd 100644 --- a/src/mongo/db/exec/sbe/sbe_test.cpp +++ b/src/mongo/db/exec/sbe/sbe_test.cpp @@ -35,16 +35,15 @@ namespace mongo::sbe { TEST(SBEValues, Basic) { - using namespace std::literals; { - const auto [tag, val] = value::makeNewString("small"sv); + const auto [tag, val] = value::makeNewString("small"_sd); ASSERT_EQUALS(tag, value::TypeTags::StringSmall); value::releaseValue(tag, val); } { - const auto [tag, val] = value::makeNewString("not so small string"sv); + const auto [tag, val] = value::makeNewString("not so small string"_sd); ASSERT_EQUALS(tag, value::TypeTags::StringBig); value::releaseValue(tag, val); @@ -53,11 +52,11 @@ TEST(SBEValues, Basic) { const auto [tag, val] = value::makeNewObject(); auto obj = value::getObjectView(val); - const auto [fieldTag, fieldVal] = value::makeNewString("not so small string"sv); - obj->push_back("field"sv, fieldTag, fieldVal); + const auto [fieldTag, fieldVal] = value::makeNewString("not so small string"_sd); + obj->push_back("field"_sd, fieldTag, fieldVal); ASSERT_EQUALS(obj->size(), 1); - const auto [checkTag, checkVal] = obj->getField("field"sv); + const auto [checkTag, checkVal] = obj->getField("field"_sd); ASSERT_EQUALS(fieldTag, checkTag); ASSERT_EQUALS(fieldVal, checkVal); @@ -68,7 +67,7 @@ TEST(SBEValues, Basic) { const auto [tag, val] = value::makeNewArray(); auto obj = value::getArrayView(val); - const auto [fieldTag, fieldVal] = value::makeNewString("not so small string"sv); + const auto [fieldTag, fieldVal] = value::makeNewString("not so small string"_sd); obj->push_back(fieldTag, fieldVal); ASSERT_EQUALS(obj->size(), 1); @@ -198,15 +197,15 @@ TEST(SBEValues, HashCompound) { { auto [tag1, val1] = value::makeNewObject(); auto obj1 = value::getObjectView(val1); - obj1->push_back("a"sv, value::TypeTags::NumberInt32, value::bitcastFrom<int32_t>(-5)); - obj1->push_back("b"sv, value::TypeTags::NumberInt32, value::bitcastFrom<int32_t>(-6)); - obj1->push_back("c"sv, value::TypeTags::NumberInt32, value::bitcastFrom<int32_t>(-7)); + obj1->push_back("a"_sd, value::TypeTags::NumberInt32, value::bitcastFrom<int32_t>(-5)); + obj1->push_back("b"_sd, value::TypeTags::NumberInt32, value::bitcastFrom<int32_t>(-6)); + obj1->push_back("c"_sd, value::TypeTags::NumberInt32, value::bitcastFrom<int32_t>(-7)); auto [tag2, val2] = value::makeNewObject(); auto obj2 = value::getObjectView(val2); - obj2->push_back("a"sv, value::TypeTags::NumberDouble, value::bitcastFrom<double>(-5.0)); - obj2->push_back("b"sv, value::TypeTags::NumberDouble, value::bitcastFrom<double>(-6.0)); - obj2->push_back("c"sv, value::TypeTags::NumberDouble, value::bitcastFrom<double>(-7.0)); + obj2->push_back("a"_sd, value::TypeTags::NumberDouble, value::bitcastFrom<double>(-5.0)); + obj2->push_back("b"_sd, value::TypeTags::NumberDouble, value::bitcastFrom<double>(-6.0)); + obj2->push_back("c"_sd, value::TypeTags::NumberDouble, value::bitcastFrom<double>(-7.0)); ASSERT_EQUALS(value::hashValue(tag1, val1), value::hashValue(tag2, val2)); diff --git a/src/mongo/db/exec/sbe/sbe_unique_test.cpp b/src/mongo/db/exec/sbe/sbe_unique_test.cpp index 08ed98c1723..812b7383b1e 100644 --- a/src/mongo/db/exec/sbe/sbe_unique_test.cpp +++ b/src/mongo/db/exec/sbe/sbe_unique_test.cpp @@ -29,7 +29,6 @@ #include "mongo/platform/basic.h" -#include <string_view> #include "mongo/db/exec/sbe/sbe_plan_stage_test.h" #include "mongo/db/exec/sbe/stages/unique.h" diff --git a/src/mongo/db/exec/sbe/stages/ix_scan.cpp b/src/mongo/db/exec/sbe/stages/ix_scan.cpp index 854af856cd2..8e70ccd2004 100644 --- a/src/mongo/db/exec/sbe/stages/ix_scan.cpp +++ b/src/mongo/db/exec/sbe/stages/ix_scan.cpp @@ -39,7 +39,7 @@ namespace mongo::sbe { IndexScanStage::IndexScanStage(CollectionUUID collUuid, - std::string_view indexName, + StringData indexName, bool forward, boost::optional<value::SlotId> recordSlot, boost::optional<value::SlotId> recordIdSlot, diff --git a/src/mongo/db/exec/sbe/stages/ix_scan.h b/src/mongo/db/exec/sbe/stages/ix_scan.h index da10c9bf126..63c583764ab 100644 --- a/src/mongo/db/exec/sbe/stages/ix_scan.h +++ b/src/mongo/db/exec/sbe/stages/ix_scan.h @@ -60,7 +60,7 @@ namespace mongo::sbe { class IndexScanStage final : public PlanStage { public: IndexScanStage(CollectionUUID collUuid, - std::string_view indexName, + StringData indexName, bool forward, boost::optional<value::SlotId> recordSlot, boost::optional<value::SlotId> recordIdSlot, diff --git a/src/mongo/db/exec/sbe/util/debug_print.cpp b/src/mongo/db/exec/sbe/util/debug_print.cpp index 939779be8de..e3d831b5ab5 100644 --- a/src/mongo/db/exec/sbe/util/debug_print.cpp +++ b/src/mongo/db/exec/sbe/util/debug_print.cpp @@ -92,20 +92,20 @@ std::string DebugPrinter::print(const std::vector<Block>& blocks) { break; } - std::string_view sv(b.str); + StringData sv(b.str); if (!sv.empty()) { - if (sv.front() == '`') { - sv.remove_prefix(1); + if (*sv.begin() == '`') { + sv = sv.substr(1); if (!ret.empty() && ret.back() == ' ') { ret.resize(ret.size() - 1, 0); } } - if (!sv.empty() && sv.back() == '`') { - sv.remove_suffix(1); + if (!sv.empty() && *(sv.end() - 1) == '`') { + sv = sv.substr(0, sv.size() - 1); addSpace = false; } if (!sv.empty()) { - ret.append(sv); + ret.append(sv.begin(), sv.end()); if (addSpace) { ret.append(" "); } diff --git a/src/mongo/db/exec/sbe/util/debug_print.h b/src/mongo/db/exec/sbe/util/debug_print.h index 19e29d7bdf4..a11bb24c75c 100644 --- a/src/mongo/db/exec/sbe/util/debug_print.h +++ b/src/mongo/db/exec/sbe/util/debug_print.h @@ -60,16 +60,16 @@ public: Command cmd; std::string str; - Block(std::string_view s) : cmd(cmdNone), str(s) {} + Block(StringData s) : cmd(cmdNone), str(s) {} - Block(Command c, std::string_view s) : cmd(c), str(s) {} + Block(Command c, StringData s) : cmd(c), str(s) {} Block(Command c) : cmd(c) {} }; DebugPrinter(bool colorConsole = false) : _colorConsole(colorConsole) {} - static void addKeyword(std::vector<Block>& ret, std::string_view k) { + static void addKeyword(std::vector<Block>& ret, StringData k) { ret.emplace_back(Block::cmdColorCyan); ret.emplace_back(Block{Block::cmdNoneNoSpace, k}); ret.emplace_back(Block::cmdColorNone); @@ -92,7 +92,7 @@ public: ret.emplace_back(Block{Block::cmdNoneNoSpace, " "}); } - static void addIdentifier(std::vector<Block>& ret, std::string_view k) { + static void addIdentifier(std::vector<Block>& ret, StringData k) { ret.emplace_back(Block::cmdColorGreen); ret.emplace_back(Block{Block::cmdNoneNoSpace, k}); ret.emplace_back(Block::cmdColorNone); diff --git a/src/mongo/db/exec/sbe/values/bson.cpp b/src/mongo/db/exec/sbe/values/bson.cpp index ea5f50b7e58..6a67127bd6f 100644 --- a/src/mongo/db/exec/sbe/values/bson.cpp +++ b/src/mongo/db/exec/sbe/values/bson.cpp @@ -290,8 +290,7 @@ void convertToBsonObj(ArrayBuilder& builder, value::ArrayEnumerator arr) { case value::TypeTags::StringSmall: case value::TypeTags::StringBig: case value::TypeTags::bsonString: { - auto sv = value::getStringView(tag, val); - builder.append(StringData{sv.data(), sv.size()}); + builder.append(value::getStringView(tag, val)); break; } case value::TypeTags::Array: { @@ -385,11 +384,9 @@ template void convertToBsonObj<UniqueBSONObjBuilder>(UniqueBSONObjBuilder& build template <class ObjBuilder> void appendValueToBsonObj(ObjBuilder& builder, - std::string_view nameSV, + StringData name, value::TypeTags tag, value::Value val) { - StringData name{nameSV.data(), nameSV.size()}; - switch (tag) { case value::TypeTags::Nothing: break; @@ -421,8 +418,7 @@ void appendValueToBsonObj(ObjBuilder& builder, case value::TypeTags::StringSmall: case value::TypeTags::StringBig: case value::TypeTags::bsonString: { - auto sv = value::getStringView(tag, val); - builder.append(name, StringData{sv.data(), sv.size()}); + builder.append(name, value::getStringView(tag, val)); break; } case value::TypeTags::Array: { @@ -485,11 +481,11 @@ void appendValueToBsonObj(ObjBuilder& builder, } template void appendValueToBsonObj<BSONObjBuilder>(BSONObjBuilder& builder, - std::string_view name, + StringData name, value::TypeTags tag, value::Value val); template void appendValueToBsonObj<UniqueBSONObjBuilder>(UniqueBSONObjBuilder& builder, - std::string_view name, + StringData name, value::TypeTags tag, value::Value val); } // namespace bson diff --git a/src/mongo/db/exec/sbe/values/bson.h b/src/mongo/db/exec/sbe/values/bson.h index a8839d511fa..af37f80f76b 100644 --- a/src/mongo/db/exec/sbe/values/bson.h +++ b/src/mongo/db/exec/sbe/values/bson.h @@ -42,7 +42,7 @@ std::pair<value::TypeTags, value::Value> convertFrom(bool view, const char* advance(const char* be, size_t fieldNameSize); inline auto fieldNameView(const char* be) noexcept { - return std::string_view{be + 1}; + return StringData{be + 1}; } template <class ArrayBuilder> @@ -53,7 +53,7 @@ void convertToBsonObj(ObjBuilder& builder, value::Object* obj); template <class ObjBuilder> void appendValueToBsonObj(ObjBuilder& builder, - std::string_view name, + StringData name, value::TypeTags tag, value::Value val); } // namespace bson diff --git a/src/mongo/db/exec/sbe/values/slot.h b/src/mongo/db/exec/sbe/values/slot.h index fbfc7239d3b..44fcde13d1d 100644 --- a/src/mongo/db/exec/sbe/values/slot.h +++ b/src/mongo/db/exec/sbe/values/slot.h @@ -633,7 +633,7 @@ void readKeyStringValueIntoAccessors( template <typename T> using SlotMap = absl::flat_hash_map<SlotId, T>; using SlotAccessorMap = SlotMap<SlotAccessor*>; -using FieldAccessorMap = absl::flat_hash_map<std::string, std::unique_ptr<ViewOfValueAccessor>>; +using FieldAccessorMap = StringMap<std::unique_ptr<ViewOfValueAccessor>>; using SlotSet = absl::flat_hash_set<SlotId>; using SlotVector = std::vector<SlotId>; diff --git a/src/mongo/db/exec/sbe/values/value.cpp b/src/mongo/db/exec/sbe/values/value.cpp index 3522679d78f..9fd512ea9d0 100644 --- a/src/mongo/db/exec/sbe/values/value.cpp +++ b/src/mongo/db/exec/sbe/values/value.cpp @@ -44,21 +44,32 @@ namespace mongo { namespace sbe { namespace value { +namespace { +template <typename T> +auto abslHash(const T& val) { + if constexpr (std::is_same_v<T, StringData>) { + return absl::Hash<absl::string_view>{}(absl::string_view{val.rawData(), val.size()}); + } else { + return absl::Hash<T>{}(val); + } +} +} // namespace + std::pair<TypeTags, Value> makeCopyBsonRegex(const BsonRegex& regex) { auto buffer = std::make_unique<char[]>(regex.byteSize()); memcpy(buffer.get(), regex.data(), regex.byteSize()); return {TypeTags::bsonRegex, bitcastFrom<char*>(buffer.release())}; } -std::pair<TypeTags, Value> makeNewBsonRegex(std::string_view pattern, std::string_view flags) { +std::pair<TypeTags, Value> makeNewBsonRegex(StringData pattern, StringData flags) { // Add 2 to account NULL bytes after pattern and flags. auto totalSize = pattern.size() + flags.size() + 2; auto buffer = std::make_unique<char[]>(totalSize); auto rawBuffer = buffer.get(); // Copy pattern first and flags after it. - memcpy(rawBuffer, pattern.data(), pattern.size()); - memcpy(rawBuffer + pattern.size() + 1, flags.data(), flags.size()); + memcpy(rawBuffer, pattern.rawData(), pattern.size()); + memcpy(rawBuffer + pattern.size() + 1, flags.rawData(), flags.size()); // Ensure NULL byte is placed after each part. rawBuffer[pattern.size()] = '\0'; @@ -66,7 +77,7 @@ std::pair<TypeTags, Value> makeNewBsonRegex(std::string_view pattern, std::strin return {TypeTags::bsonRegex, bitcastFrom<char*>(buffer.release())}; } -std::pair<TypeTags, Value> makeCopyBsonJavascript(std::string_view code) { +std::pair<TypeTags, Value> makeCopyBsonJavascript(StringData code) { auto [_, strVal] = makeBigString(code); return {TypeTags::bsonJavascript, strVal}; } @@ -76,7 +87,7 @@ std::pair<TypeTags, Value> makeCopyKeyString(const KeyString::Value& inKey) { return {TypeTags::ksValue, bitcastFrom<KeyString::Value*>(k)}; } -std::pair<TypeTags, Value> makeNewPcreRegex(std::string_view pattern, std::string_view options) { +std::pair<TypeTags, Value> makeNewPcreRegex(StringData pattern, StringData options) { auto regex = std::make_unique<PcreRegex>(pattern, options); return {TypeTags::pcreRegex, bitcastFrom<PcreRegex*>(regex.release())}; } @@ -94,11 +105,11 @@ void PcreRegex::_compile() { uassert(5073402, str::stream() << "Invalid Regex: " << compile_error, _pcrePtr != nullptr); } -int PcreRegex::execute(std::string_view stringView, int startPos, std::vector<int>& buf) { +int PcreRegex::execute(StringData stringView, int startPos, std::vector<int>& buf) { return pcre_exec(_pcrePtr, nullptr, - stringView.data(), - stringView.length(), + stringView.rawData(), + stringView.size(), startPos, 0, &(buf.front()), @@ -417,11 +428,11 @@ void writeValueToStream(T& stream, TypeTags tag, Value val) { case TypeTags::StringBig: case TypeTags::bsonString: { auto sv = getStringView(tag, val); - if (sv.length() <= kStringMaxDisplayLength) { - stream << '"' << StringData{sv.data(), sv.size()} << '"'; + if (sv.size() <= kStringMaxDisplayLength) { + stream << '"' << sv << '"'; } else { auto sub = sv.substr(0, kStringMaxDisplayLength); - stream << '"' << StringData{sub.data(), sub.size()} << '"' << "..."; + stream << '"' << sub << '"' << "..."; } break; } @@ -595,36 +606,35 @@ BSONType tagToType(TypeTags tag) noexcept { std::size_t hashValue(TypeTags tag, Value val, const CollatorInterface* collator) noexcept { switch (tag) { case TypeTags::NumberInt32: - return absl::Hash<int32_t>{}(bitcastTo<int32_t>(val)); + return abslHash(bitcastTo<int32_t>(val)); case TypeTags::RecordId: case TypeTags::NumberInt64: - return absl::Hash<int64_t>{}(bitcastTo<int64_t>(val)); + return abslHash(bitcastTo<int64_t>(val)); case TypeTags::NumberDouble: { // Force doubles to integers for hashing. auto dbl = bitcastTo<double>(val); if (auto asInt = representAs<int64_t>(dbl); asInt) { - return absl::Hash<int64_t>{}(*asInt); + return abslHash(*asInt); } else { // Doubles not representable as int64_t will hash as doubles. - return absl::Hash<double>{}(dbl); + return abslHash(dbl); } } case TypeTags::NumberDecimal: { // Force decimals to integers for hashing. auto dec = bitcastTo<Decimal128>(val); if (auto asInt = representAs<int64_t>(dec); asInt) { - return absl::Hash<int64_t>{}(*asInt); + return abslHash(*asInt); } else if (auto asDbl = representAs<double>(dec); asDbl) { - return absl::Hash<double>{}(*asDbl); + return abslHash(*asDbl); } else { - return absl::Hash<uint64_t>{}(dec.getValue().low64) ^ - absl::Hash<uint64_t>{}(dec.getValue().high64); + return abslHash(dec.getValue().low64) ^ abslHash(dec.getValue().high64); } } case TypeTags::Date: - return absl::Hash<int64_t>{}(bitcastTo<int64_t>(val)); + return abslHash(bitcastTo<int64_t>(val)); case TypeTags::Timestamp: - return absl::Hash<uint64_t>{}(bitcastTo<uint64_t>(val)); + return abslHash(bitcastTo<uint64_t>(val)); case TypeTags::Boolean: return bitcastTo<bool>(val); case TypeTags::Null: @@ -637,18 +647,15 @@ std::size_t hashValue(TypeTags tag, Value val, const CollatorInterface* collator case TypeTags::bsonString: { auto sv = getStringView(tag, val); if (collator) { - auto key = collator->getComparisonKey(StringData{sv.data(), sv.size()}); - auto keyData = key.getKeyData(); - return absl::Hash<std::string_view>{}( - std::string_view{keyData.rawData(), keyData.size()}); + return abslHash(collator->getComparisonKey(sv).getKeyData()); } else { - return absl::Hash<std::string_view>{}(sv); + return abslHash(sv); } } case TypeTags::ObjectId: { auto id = getObjectIdView(val); - return absl::Hash<uint64_t>{}(readFromMemory<uint64_t>(id->data())) ^ - absl::Hash<uint32_t>{}(readFromMemory<uint32_t>(id->data() + 8)); + return abslHash(readFromMemory<uint64_t>(id->data())) ^ + abslHash(readFromMemory<uint32_t>(id->data() + 8)); } case TypeTags::ksValue: { return getKeyStringView(val)->hash(); @@ -690,19 +697,19 @@ std::size_t hashValue(TypeTags tag, Value val, const CollatorInterface* collator memcpy(buffer, getRawPointerView(val), size); // Hash as if it is 64bit integer. - return absl::Hash<uint64_t>{}(readFromMemory<uint64_t>(buffer)); + return abslHash(readFromMemory<uint64_t>(buffer)); } else { // Hash only the first 8 bytes. It should be enough. - return absl::Hash<uint64_t>{}( + return abslHash( readFromMemory<uint64_t>(getRawPointerView(val) + sizeof(uint32_t))); } } case TypeTags::bsonRegex: { auto regex = getBsonRegexView(val); - return absl::Hash<std::string_view>{}(regex.dataView()); + return abslHash(regex.dataView()); } case TypeTags::bsonJavascript: - return absl::Hash<std::string_view>{}(getBsonJavascriptView(val)); + return abslHash(getBsonJavascriptView(val)); default: break; } @@ -715,7 +722,7 @@ std::size_t hashValue(TypeTags tag, Value val, const CollatorInterface* collator * guarantees that the result will be exactlty -1, 0, or 1, which is important, because not all * comparison functions make that guarantee. * - * The std::string_view::compare(basic_string_view s) function, for example, only promises that it + * The StringData::compare(basic_string_view s) function, for example, only promises that it * will return a value less than 0 in the case that 'this' is less than 's,' whereas we want to * return exactly -1. */ @@ -761,9 +768,7 @@ std::pair<TypeTags, Value> compareValue(TypeTags lhsTag, auto lhsStr = getStringView(lhsTag, lhsValue); auto rhsStr = getStringView(rhsTag, rhsValue); - auto result = comparator ? comparator->compare(StringData{lhsStr.data(), lhsStr.size()}, - StringData{rhsStr.data(), rhsStr.size()}) - : lhsStr.compare(rhsStr); + auto result = comparator ? comparator->compare(lhsStr, rhsStr) : lhsStr.compare(rhsStr); return {TypeTags::NumberInt32, bitcastFrom<int32_t>(compareHelper(result, 0))}; } else if (lhsTag == TypeTags::Date && rhsTag == TypeTags::Date) { @@ -969,19 +974,19 @@ bool ObjectEnumerator::advance() { } } -std::string_view ObjectEnumerator::getFieldName() const { +StringData ObjectEnumerator::getFieldName() const { using namespace std::literals; if (_object) { if (_index < _object->size()) { return _object->field(_index); } else { - return ""sv; + return ""_sd; } } else { if (*_objectCurrent != 0) { return bson::fieldNameView(_objectCurrent); } else { - return ""sv; + return ""_sd; } } } diff --git a/src/mongo/db/exec/sbe/values/value.h b/src/mongo/db/exec/sbe/values/value.h index 31ade47676d..a70a48bbbee 100644 --- a/src/mongo/db/exec/sbe/values/value.h +++ b/src/mongo/db/exec/sbe/values/value.h @@ -422,7 +422,7 @@ public: } } - void push_back(std::string_view name, TypeTags tag, Value val) { + void push_back(StringData name, TypeTags tag, Value val) { if (tag != TypeTags::Nothing) { ValueGuard guard{tag, val}; // Reserve space in all vectors, they are the same size. We arbitrarily picked _typeTags @@ -437,7 +437,7 @@ public: } } - std::pair<TypeTags, Value> getField(std::string_view field) { + std::pair<TypeTags, Value> getField(StringData field) { for (size_t idx = 0; idx < _typeTags.size(); ++idx) { if (_names[idx] == field) { return {_typeTags[idx], _values[idx]}; @@ -597,12 +597,11 @@ private: */ class PcreRegex { public: - PcreRegex(std::string_view pattern, std::string_view options) - : _pattern(pattern), _options(options) { + PcreRegex(StringData pattern, StringData options) : _pattern(pattern), _options(options) { _compile(); } - PcreRegex(std::string_view pattern) : PcreRegex(pattern, "") {} + PcreRegex(StringData pattern) : PcreRegex(pattern, "") {} PcreRegex(const PcreRegex& other) : PcreRegex(other._pattern, other._options) {} @@ -639,7 +638,7 @@ public: * = 0 there was a match, but not enough space in the buffer * > 0 the number of matches */ - int execute(std::string_view input, int startPos, std::vector<int>& buf); + int execute(StringData input, int startPos, std::vector<int>& buf); size_t getNumberCaptures() const; @@ -715,7 +714,7 @@ inline size_t getStringLength(TypeTags tag, const Value& val) noexcept { /** * getStringView() should be preferred over getRawStringView() where possible. */ -inline std::string_view getStringView(TypeTags tag, const Value& val) noexcept { +inline StringData getStringView(TypeTags tag, const Value& val) noexcept { return {getRawStringView(tag, val), getStringLength(tag, val)}; } @@ -776,9 +775,9 @@ inline uint8_t* getBSONBinDataCompat(TypeTags tag, Value val) { } } -inline bool canUseSmallString(std::string_view input) { +inline bool canUseSmallString(StringData input) { auto length = input.size(); - auto ptr = input.data(); + auto ptr = input.rawData(); auto end = ptr + length; return length <= kSmallStringMaxLength && std::find(ptr, end, '\0') == end; } @@ -787,18 +786,18 @@ inline bool canUseSmallString(std::string_view input) { * Callers must check that canUseSmallString() returns true before calling this function. * makeNewString() should be preferred over makeSmallString() where possible. */ -inline std::pair<TypeTags, Value> makeSmallString(std::string_view input) { +inline std::pair<TypeTags, Value> makeSmallString(StringData input) { dassert(canUseSmallString(input)); Value smallString{0}; auto buf = getRawStringView(TypeTags::StringSmall, smallString); - memcpy(buf, input.data(), input.size()); + memcpy(buf, input.rawData(), input.size()); return {TypeTags::StringSmall, smallString}; } -inline std::pair<TypeTags, Value> makeBigString(std::string_view input) { +inline std::pair<TypeTags, Value> makeBigString(StringData input) { auto len = input.size(); - auto ptr = input.data(); + auto ptr = input.rawData(); invariant(len < static_cast<uint32_t>(std::numeric_limits<int32_t>::max())); @@ -810,7 +809,7 @@ inline std::pair<TypeTags, Value> makeBigString(std::string_view input) { return {TypeTags::StringBig, reinterpret_cast<Value>(buf)}; } -inline std::pair<TypeTags, Value> makeNewString(std::string_view input) { +inline std::pair<TypeTags, Value> makeNewString(StringData input) { if (canUseSmallString(input)) { return makeSmallString(input); } else { @@ -886,7 +885,7 @@ inline KeyString::Value* getKeyStringView(Value val) noexcept { return reinterpret_cast<KeyString::Value*>(val); } -std::pair<TypeTags, Value> makeNewPcreRegex(std::string_view pattern, std::string_view options); +std::pair<TypeTags, Value> makeNewPcreRegex(StringData pattern, StringData options); std::pair<TypeTags, Value> makeCopyPcreRegex(const PcreRegex& regex); @@ -923,13 +922,13 @@ struct BsonRegex { BsonRegex(const char* rawValue) { pattern = rawValue; // We add 1 to account NULL byte after pattern. - flags = pattern.data() + pattern.size() + 1; + flags = pattern.rawData() + pattern.size() + 1; } - BsonRegex(std::string_view pattern, std::string_view flags) : pattern(pattern), flags(flags) { + BsonRegex(StringData pattern, StringData flags) : pattern(pattern), flags(flags) { // Ensure that flags follow right after pattern in memory. Otherwise 'dataView()' may return - // invalid 'std::string_view' object. - invariant(pattern.data() + pattern.size() + 1 == flags.data()); + // invalid 'StringData' object. + invariant(pattern.rawData() + pattern.size() + 1 == flags.rawData()); } size_t byteSize() const { @@ -938,15 +937,15 @@ struct BsonRegex { } const char* data() const { - return pattern.data(); + return pattern.rawData(); } - std::string_view dataView() const { + StringData dataView() const { return {data(), byteSize()}; } - std::string_view pattern; - std::string_view flags; + StringData pattern; + StringData flags; }; inline BsonRegex getBsonRegexView(Value val) noexcept { @@ -955,13 +954,13 @@ inline BsonRegex getBsonRegexView(Value val) noexcept { std::pair<TypeTags, Value> makeCopyBsonRegex(const BsonRegex& regex); -std::pair<TypeTags, Value> makeNewBsonRegex(std::string_view pattern, std::string_view flags); +std::pair<TypeTags, Value> makeNewBsonRegex(StringData pattern, StringData flags); -inline std::string_view getBsonJavascriptView(Value val) noexcept { +inline StringData getBsonJavascriptView(Value val) noexcept { return getStringView(TypeTags::StringBig, val); } -std::pair<TypeTags, Value> makeCopyBsonJavascript(std::string_view code); +std::pair<TypeTags, Value> makeCopyBsonJavascript(StringData code); std::pair<TypeTags, Value> makeCopyKeyString(const KeyString::Value& inKey); @@ -1146,7 +1145,7 @@ public: } } std::pair<TypeTags, Value> getViewOfValue() const; - std::string_view getFieldName() const; + StringData getFieldName() const; bool atEnd() const { if (_object) { diff --git a/src/mongo/db/exec/sbe/values/value_serialize_for_sorter_test.cpp b/src/mongo/db/exec/sbe/values/value_serialize_for_sorter_test.cpp index 766bdac983a..3eedbc5dfbb 100644 --- a/src/mongo/db/exec/sbe/values/value_serialize_for_sorter_test.cpp +++ b/src/mongo/db/exec/sbe/values/value_serialize_for_sorter_test.cpp @@ -58,16 +58,16 @@ TEST(ValueSerializeForSorter, Serialize) { testData->push_back(value::TypeTags::MaxKey, 0); testData->push_back(value::TypeTags::bsonUndefined, 0); - std::string_view smallString = "perfect"; + StringData smallString = "perfect"; invariant(sbe::value::canUseSmallString(smallString)); - std::string_view bigString = "too big string to fit into value"; + StringData bigString = "too big string to fit into value"; invariant(!sbe::value::canUseSmallString(bigString)); - std::string_view smallStringWithNull = "a\0b"; + StringData smallStringWithNull = "a\0b"; invariant(smallStringWithNull.size() <= sbe::value::kSmallStringMaxLength); - std::string_view bigStringWithNull = "too big string \0 to fit into value"; + StringData bigStringWithNull = "too big string \0 to fit into value"; invariant(bigStringWithNull.size() > sbe::value::kSmallStringMaxLength); - std::vector<std::string_view> stringCases = { + std::vector<StringData> stringCases = { smallString, smallStringWithNull, bigString, diff --git a/src/mongo/db/exec/sbe/vm/datetime.cpp b/src/mongo/db/exec/sbe/vm/datetime.cpp index 09c4188ea17..84839a4a2d4 100644 --- a/src/mongo/db/exec/sbe/vm/datetime.cpp +++ b/src/mongo/db/exec/sbe/vm/datetime.cpp @@ -45,9 +45,7 @@ bool isValidTimezone(value::TypeTags timezoneTag, return false; } auto timezoneStringView = value::getStringView(timezoneTag, timezoneValue); - return timezoneStringView.empty() || - timezoneDB->isTimeZoneIdentifier( - StringData{timezoneStringView.data(), timezoneStringView.size()}); + return timezoneStringView.empty() || timezoneDB->isTimeZoneIdentifier(timezoneStringView); } TimeZone getTimezone(value::TypeTags timezoneTag, @@ -57,7 +55,7 @@ TimeZone getTimezone(value::TypeTags timezoneTag, if (timezoneStr.empty()) { return timezoneDB->utcZone(); } else { - return timezoneDB->getTimeZone(StringData{timezoneStr.data(), timezoneStr.size()}); + return timezoneDB->getTimeZone(timezoneStr); } } diff --git a/src/mongo/db/exec/sbe/vm/vm.cpp b/src/mongo/db/exec/sbe/vm/vm.cpp index dd207101ee6..09361aaea04 100644 --- a/src/mongo/db/exec/sbe/vm/vm.cpp +++ b/src/mongo/db/exec/sbe/vm/vm.cpp @@ -750,12 +750,9 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::aggLast(value::TypeTag } -bool hasSeparatorAt(size_t idx, std::string_view input, std::string_view separator) { - if (separator.size() + idx > input.size()) { - return false; - } - - return input.compare(idx, separator.size(), separator) == 0; +bool hasSeparatorAt(size_t idx, StringData input, StringData separator) { + return (idx + separator.size() <= input.size()) && + input.substr(idx, separator.size()) == separator; } std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinSplit(ArityType arity) { @@ -775,7 +772,7 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinSplit(ArityType size_t splitStart = 0; size_t splitPos; - while ((splitPos = input.find(separator, splitStart)) != std::string_view::npos) { + while ((splitPos = input.find(separator, splitStart)) != std::string::npos) { auto [tag, val] = value::makeNewString(input.substr(splitStart, splitPos - splitStart)); arr->push_back(tag, val); @@ -835,7 +832,7 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinDropFields(Arit } else if (tagInObj == value::TypeTags::Object) { auto objRoot = value::getObjectView(valInObj); for (size_t idx = 0; idx < objRoot->size(); ++idx) { - std::string_view sv(objRoot->field(idx)); + StringData sv(objRoot->field(idx)); if (restrictFieldsSet.count(sv) == 0) { @@ -947,7 +944,7 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinNewKeyString(Ar kb.appendNumberLong(num); } else if (value::isString(tag)) { auto str = value::getStringView(tag, val); - kb.appendString(StringData{str.data(), str.length()}); + kb.appendString(str); } else { uasserted(4822802, "unsuppored key string type"); } @@ -1154,20 +1151,16 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinReplaceOne(Arit return {false, value::TypeTags::Nothing, 0}; } - auto inputStrView = value::getStringView(typeTagInputStr, valueInputStr); - auto findStrView = value::getStringView(typeTagFindStr, valueFindStr); - auto replacementStrView = value::getStringView(typeTagReplacementStr, valueReplacementStr); + auto input = value::getStringView(typeTagInputStr, valueInputStr); + auto find = value::getStringView(typeTagFindStr, valueFindStr); + auto replacement = value::getStringView(typeTagReplacementStr, valueReplacementStr); // If find string is empty, return nothing, since an empty find will match every position in a // string. - if (findStrView.empty()) { + if (find.empty()) { return {false, value::TypeTags::Nothing, 0}; } - auto input = StringData(inputStrView.data(), inputStrView.length()); - auto find = StringData(findStrView.data(), findStrView.length()); - auto replacement = StringData(replacementStrView.data(), replacementStrView.length()); - // If find string is not found, return the original string. size_t startIndex = input.find(find); if (startIndex == std::string::npos) { @@ -1182,8 +1175,7 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinReplaceOne(Arit output << input.substr(endIndex); auto strData = output.stringData(); - auto [outputStrTypeTag, outputStrValue] = - sbe::value::makeNewString({strData.rawData(), strData.size()}); + auto [outputStrTypeTag, outputStrValue] = sbe::value::makeNewString(strData); return {true, outputStrTypeTag, outputStrValue}; } @@ -1321,9 +1313,7 @@ std::tuple<bool, value::TypeTags, value::Value> builtinDateHelper( invariant(timeZoneDB); auto tzString = value::getStringView(typeTagTz, valueTz); - const auto tz = tzString == "" - ? timeZoneDB->utcZone() - : timeZoneDB->getTimeZone(StringData{tzString.data(), tzString.size()}); + const auto tz = tzString == "" ? timeZoneDB->utcZone() : timeZoneDB->getTimeZone(tzString); auto date = computeDateFn(tz, @@ -1858,8 +1848,7 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinConcat(ArityTyp if (!value::isString(tag)) { return {false, value::TypeTags::Nothing, 0}; } - auto sv = sbe::value::getStringView(tag, value); - result << StringData{sv.data(), sv.size()}; + result << sbe::value::getStringView(tag, value); } auto [strTag, strValue] = sbe::value::makeNewString(result.str()); @@ -1956,7 +1945,7 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinIndexOfBytes(Ar return {false, value::TypeTags::Nothing, 0}; } // Check for valid bounds. - if (static_cast<size_t>(startIndex) > str.length()) { + if (static_cast<size_t>(startIndex) > str.size()) { return {false, value::TypeTags::NumberInt32, value::bitcastFrom<int32_t>(-1)}; } } @@ -2003,7 +1992,7 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinIndexOfCP(Arity return {false, value::TypeTags::Nothing, 0}; } // Check for valid bounds. - if (static_cast<size_t>(startCodePointIndex) > str.length()) { + if (static_cast<size_t>(startCodePointIndex) > str.size()) { return {false, value::TypeTags::NumberInt32, value::bitcastFrom<int32_t>(-1)}; } } @@ -2044,7 +2033,7 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinIndexOfCP(Arity byteIndex = startByteIndex; for (codePointIndex = startCodePointIndex; codePointIndex < endCodePointIndex; ++codePointIndex) { - if (str.compare(byteIndex, substr.size(), substr) == 0) { + if (str.substr(byteIndex, substr.size()).compare(substr) == 0) { return { false, value::TypeTags::NumberInt32, value::bitcastFrom<int32_t>(codePointIndex)}; } @@ -2088,7 +2077,7 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinIsTimezone(Arit return {false, value::TypeTags::Boolean, false}; } auto timezoneStr = value::getStringView(timezoneTag, timezoneVal); - if (timezoneDB->isTimeZoneIdentifier((StringData{timezoneStr.data(), timezoneStr.size()}))) { + if (timezoneDB->isTimeZoneIdentifier(timezoneStr)) { return {false, value::TypeTags::Boolean, true}; } return {false, value::TypeTags::Boolean, false}; @@ -2322,7 +2311,7 @@ namespace { * ...} from the result of pcre_exec(). */ std::tuple<bool, value::TypeTags, value::Value> buildRegexMatchResultObject( - std::string_view inputString, + StringData inputString, const std::vector<int>& capturesBuffer, size_t numCaptures, uint32_t& startBytePos, @@ -2419,7 +2408,7 @@ std::tuple<bool, value::TypeTags, value::Value> buildRegexMatchResultObject( * returned is true/false. */ std::tuple<bool, value::TypeTags, value::Value> pcreNextMatch(value::PcreRegex* pcre, - std::string_view inputString, + StringData inputString, std::vector<int>& capturesBuffer, uint32_t& startBytePos, uint32_t& codePointPos, @@ -2454,7 +2443,7 @@ std::tuple<bool, value::TypeTags, value::Value> pcreNextMatch(value::PcreRegex* */ std::tuple<bool, value::TypeTags, value::Value> pcreFirstMatch( value::PcreRegex* pcre, - std::string_view inputString, + StringData inputString, bool isMatch = false, std::vector<int>* capturesBuffer = nullptr, uint32_t* startBytePos = nullptr, @@ -2507,16 +2496,15 @@ std::pair<value::TypeTags, value::Value> collComparisonKey(value::TypeTags tag, // For strings, call CollatorInterface::getComparisonKey() to obtain the comparison key. if (value::isString(tag)) { - auto sv = value::getStringView(tag, val); - auto compKey = collator->getComparisonKey(StringData{sv.data(), sv.size()}); + auto compKey = collator->getComparisonKey(value::getStringView(tag, val)); auto keyData = compKey.getKeyData(); - return value::makeNewString(std::string_view{keyData.rawData(), keyData.size()}); + return value::makeNewString(keyData); } // For collatable types other than strings (such as arrays and objects), we take the slow // path and round-trip the value through BSON. BSONObjBuilder input; - bson::appendValueToBsonObj<BSONObjBuilder>(input, ""sv, tag, val); + bson::appendValueToBsonObj<BSONObjBuilder>(input, ""_sd, tag, val); BSONObjBuilder output; CollationIndexKey::collationAwareIndexKeyAppend(input.obj().firstElement(), collator, &output); @@ -2625,8 +2613,8 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinRegexFindAll(Ar startBytePos += str::getCodePointLength(inputString[startBytePos]); ++codePointPos; } else { - startBytePos += matchString.length(); - for (size_t byteIdx = 0; byteIdx < matchString.length(); ++codePointPos) { + startBytePos += matchString.size(); + for (size_t byteIdx = 0; byteIdx < matchString.size(); ++codePointPos) { byteIdx += str::getCodePointLength(matchString[byteIdx]); } } @@ -2801,7 +2789,7 @@ std::tuple<bool, value::TypeTags, value::Value> ByteCode::builtinHasNullBytes(Ar } auto stringView = value::getStringView(strType, strValue); - auto hasNullBytes = stringView.find('\0') != std::string_view::npos; + auto hasNullBytes = stringView.find('\0') != std::string::npos; return {false, value::TypeTags::Boolean, value::bitcastFrom<bool>(hasNullBytes)}; } diff --git a/src/mongo/db/exec/sbe/vm/vm.h b/src/mongo/db/exec/sbe/vm/vm.h index b98f3261d12..1d11e835858 100644 --- a/src/mongo/db/exec/sbe/vm/vm.h +++ b/src/mongo/db/exec/sbe/vm/vm.h @@ -79,10 +79,8 @@ std::pair<value::TypeTags, value::Value> genericCompare( auto lhsStr = getStringView(lhsTag, lhsValue); auto rhsStr = getStringView(rhsTag, rhsValue); - auto result = op(comparator ? comparator->compare(StringData{lhsStr.data(), lhsStr.size()}, - StringData{rhsStr.data(), rhsStr.size()}) - : lhsStr.compare(rhsStr), - 0); + auto result = + op(comparator ? comparator->compare(lhsStr, rhsStr) : lhsStr.compare(rhsStr), 0); return {value::TypeTags::Boolean, value::bitcastFrom<bool>(result)}; } else if (lhsTag == value::TypeTags::Date && rhsTag == value::TypeTags::Date) { diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp index 0db59301a5c..f008c6e7b4c 100644 --- a/src/mongo/db/pipeline/expression.cpp +++ b/src/mongo/db/pipeline/expression.cpp @@ -1972,12 +1972,8 @@ TimeUnit ExpressionDateDiff::convertToTimeUnit(const Value& value) { str::stream() << "$dateDiff requires 'unit' to be a string, but got " << typeName(value.getType()), BSONType::String == value.getType()); - auto valueAsString = value.getStringData(); - return addContextToAssertionException( - [&]() { - return parseTimeUnit(std::string_view{valueAsString.rawData(), valueAsString.size()}); - }, - "$dateDiff parameter 'unit' value parsing failed"_sd); + return addContextToAssertionException([&] { return parseTimeUnit(value.getStringData()); }, + "$dateDiff parameter 'unit' value parsing failed"_sd); } DayOfWeek ExpressionDateDiff::parseStartOfWeek(const Value& value) { @@ -1985,11 +1981,8 @@ DayOfWeek ExpressionDateDiff::parseStartOfWeek(const Value& value) { str::stream() << "$dateDiff requires 'startOfWeek' to be a string, but got " << typeName(value.getType()), BSONType::String == value.getType()); - auto valueAsString = value.getStringData(); return addContextToAssertionException( - [&]() { - return parseDayOfWeek(std::string_view{valueAsString.rawData(), valueAsString.size()}); - }, + [&] { return parseDayOfWeek(value.getStringData()); }, "$dateDiff parameter 'startOfWeek' value parsing failed"_sd); } diff --git a/src/mongo/db/query/sbe_stage_builder.cpp b/src/mongo/db/query/sbe_stage_builder.cpp index 6b99a116b3d..dbbb9093759 100644 --- a/src/mongo/db/query/sbe_stage_builder.cpp +++ b/src/mongo/db/query/sbe_stage_builder.cpp @@ -454,11 +454,10 @@ std::pair<std::unique_ptr<sbe::PlanStage>, PlanStageSlots> SlotBasedStageBuilder for (auto&& field : vsn->indexKeyPattern) { if (reqs.getIndexKeyBitset()->test(indexKeyPos)) { indexKeySlots.push_back(_slotIdGenerator.generate()); - projections.emplace( - indexKeySlots.back(), - makeFunction("getField"sv, - sbe::makeE<sbe::EVariable>(resultSlot), - makeConstant(std::string_view{field.fieldName()}))); + projections.emplace(indexKeySlots.back(), + makeFunction("getField"_sd, + sbe::makeE<sbe::EVariable>(resultSlot), + makeConstant(field.fieldName()))); } ++indexKeyPos; } @@ -515,10 +514,7 @@ std::pair<std::unique_ptr<sbe::PlanStage>, PlanStageSlots> SlotBasedStageBuilder size_t i = 0; for (auto&& elem : ixn->index.keyPattern) { - auto fieldName = elem.fieldNameStringData(); - - mkObjArgs.emplace_back(sbe::makeE<sbe::EConstant>( - std::string_view{fieldName.rawData(), fieldName.size()})); + mkObjArgs.emplace_back(sbe::makeE<sbe::EConstant>(elem.fieldNameStringData())); mkObjArgs.emplace_back(sbe::makeE<sbe::EVariable>((*outputs.getIndexKeySlots())[i++])); } @@ -718,20 +714,19 @@ std::pair<std::unique_ptr<sbe::PlanStage>, PlanStageSlots> SlotBasedStageBuilder // Generate projection to get the value of the sort key. Ideally, this should be // tracked by a 'reference tracker' at higher level. auto fieldName = part.fieldPath->getFieldName(0); - auto fieldNameSV = std::string_view{fieldName.rawData(), fieldName.size()}; - auto getSortFieldExpr = makeFunction("getField"sv, + auto getSortFieldExpr = makeFunction("getField"_sd, sbe::makeE<sbe::EVariable>(outputs.get(kResult)), - sbe::makeE<sbe::EConstant>(fieldNameSV)); + sbe::makeE<sbe::EConstant>(fieldName)); if (auto collatorSlot = _data.env->getSlotIfExists("collator"_sd); collatorSlot) { - getSortFieldExpr = makeFunction("collComparisonKey"sv, + getSortFieldExpr = makeFunction("collComparisonKey"_sd, std::move(getSortFieldExpr), sbe::makeE<sbe::EVariable>(*collatorSlot)); } // According to MQL semantics, missing values are treated as nulls during sorting. - getSortFieldExpr = makeFunction("fillEmpty"sv, + getSortFieldExpr = makeFunction("fillEmpty"_sd, std::move(getSortFieldExpr), makeConstant(sbe::value::TypeTags::Null, 0)); @@ -1367,7 +1362,7 @@ SlotBasedStageBuilder::makeUnionForTailableCollScan(const QuerySolutionNode* roo auto&& [anchorBranchSlots, anchorBranch] = makeUnionBranch(false); anchorBranch = sbe::makeS<sbe::FilterStage<true>>( std::move(anchorBranch), - makeNot(makeFunction("exists"sv, sbe::makeE<sbe::EVariable>(resumeRecordIdSlot))), + makeNot(makeFunction("exists"_sd, sbe::makeE<sbe::EVariable>(resumeRecordIdSlot))), root->nodeId()); // Build a resume branch of the union and add a constant filter on op of it, so that it would @@ -1375,7 +1370,7 @@ SlotBasedStageBuilder::makeUnionForTailableCollScan(const QuerySolutionNode* roo auto&& [resumeBranchSlots, resumeBranch] = makeUnionBranch(true); resumeBranch = sbe::makeS<sbe::FilterStage<true>>( sbe::makeS<sbe::LimitSkipStage>(std::move(resumeBranch), boost::none, 1, root->nodeId()), - sbe::makeE<sbe::EFunction>("exists"sv, + sbe::makeE<sbe::EFunction>("exists"_sd, sbe::makeEs(sbe::makeE<sbe::EVariable>(resumeRecordIdSlot))), root->nodeId()); diff --git a/src/mongo/db/query/sbe_stage_builder_expression.cpp b/src/mongo/db/query/sbe_stage_builder_expression.cpp index 4b0de4bdbfd..45ef557b5a5 100644 --- a/src/mongo/db/query/sbe_stage_builder_expression.cpp +++ b/src/mongo/db/query/sbe_stage_builder_expression.cpp @@ -182,15 +182,12 @@ std::pair<sbe::value::SlotId, EvalStage> generateTraverseHelper( // Generate the projection stage to read a sub-field at the current nested level and bind it // to 'fieldSlot'. - inputStage = makeProject( - std::move(inputStage), - planNodeId, - fieldSlot, - makeFunction( - "getField"sv, sbe::makeE<sbe::EVariable>(inputSlot), sbe::makeE<sbe::EConstant>([&]() { - auto fieldName = fp.getFieldName(level); - return std::string_view{fieldName.rawData(), fieldName.size()}; - }()))); + inputStage = makeProject(std::move(inputStage), + planNodeId, + fieldSlot, + makeFunction("getField"_sd, + sbe::makeE<sbe::EVariable>(inputSlot), + sbe::makeE<sbe::EConstant>(fp.getFieldName(level)))); EvalStage innerBranch; if (level == fp.getPathLength() - 1) { @@ -1228,7 +1225,7 @@ public: // Get child expressions. auto startOfWeekExpression = expr->isStartOfWeekSpecified() ? _context->popExpr() : nullptr; auto timezoneExpression = - expr->isTimezoneSpecified() ? _context->popExpr() : makeConstant("UTC"sv); + expr->isTimezoneSpecified() ? _context->popExpr() : makeConstant("UTC"_sd); auto unitExpression = _context->popExpr(); auto endDateExpression = _context->popExpr(); auto startDateExpression = _context->popExpr(); @@ -1247,7 +1244,7 @@ public: // "dateDiff" built-in function does not accept non-string type values for this // parameter. arguments.push_back(sbe::makeE<sbe::EIf>( - unitIsWeekRef.clone(), startOfWeekRef.clone(), makeConstant("sun"sv))); + unitIsWeekRef.clone(), startOfWeekRef.clone(), makeConstant("sun"_sd))); } // Set bindings for the frame. @@ -1257,11 +1254,11 @@ public: bindings.push_back(std::move(timezoneExpression)); if (expr->isStartOfWeekSpecified()) { bindings.push_back(std::move(startOfWeekExpression)); - bindings.push_back(generateIsEqualToStringCheck(unitRef, "week"sv)); + bindings.push_back(generateIsEqualToStringCheck(unitRef, "week"_sd)); } // Create an expression to invoke built-in "dateDiff" function. - auto dateDiffFunctionCall = sbe::makeE<sbe::EFunction>("dateDiff"sv, std::move(arguments)); + auto dateDiffFunctionCall = sbe::makeE<sbe::EFunction>("dateDiff"_sd, std::move(arguments)); // Create expressions to check that each argument to "dateDiff" function exists, is not // null, and is of the correct type. @@ -2853,7 +2850,7 @@ private: * Creates a boolean expression to check if 'variable' is equal to string 'string'. */ static std::unique_ptr<sbe::EExpression> generateIsEqualToStringCheck( - const sbe::EVariable& variable, std::string_view string) { + const sbe::EVariable& variable, StringData string) { return sbe::makeE<sbe::EPrimBinary>(sbe::EPrimBinary::logicAnd, makeFunction("isString", variable.clone()), sbe::makeE<sbe::EPrimBinary>(sbe::EPrimBinary::eq, @@ -3078,14 +3075,15 @@ private: switch (setOp) { case SetOperation::Difference: return std::make_pair("setDifference"_sd, - collatorSlot ? "collSetDifference"sv : "setDifference"sv); + collatorSlot ? "collSetDifference"_sd + : "setDifference"_sd); case SetOperation::Intersection: return std::make_pair("setIntersection"_sd, - collatorSlot ? "collSetIntersection"sv - : "setIntersection"sv); + collatorSlot ? "collSetIntersection"_sd + : "setIntersection"_sd); case SetOperation::Union: return std::make_pair("setUnion"_sd, - collatorSlot ? "collSetUnion"sv : "setUnion"sv); + collatorSlot ? "collSetUnion"_sd : "setUnion"_sd); default: MONGO_UNREACHABLE; } diff --git a/src/mongo/db/query/sbe_stage_builder_filter.cpp b/src/mongo/db/query/sbe_stage_builder_filter.cpp index 1f4d65eb4ba..9d9c8ebaefa 100644 --- a/src/mongo/db/query/sbe_stage_builder_filter.cpp +++ b/src/mongo/db/query/sbe_stage_builder_filter.cpp @@ -332,13 +332,13 @@ EvalExprStagePair generatePathTraversal(EvalStage inputStage, // Generate the projection stage to read a sub-field at the current nested level and bind it // to 'fieldSlot'. - std::string_view fieldName{fp.getPart(level).rawData(), fp.getPart(level).size()}; + auto fieldName = fp.getPart(level); auto fieldSlot{slotIdGenerator->generate()}; auto fromBranch = makeProject(std::move(inputStage), planNodeId, fieldSlot, - sbe::makeE<sbe::EFunction>("getField"sv, + sbe::makeE<sbe::EFunction>("getField"_sd, sbe::makeEs(sbe::makeE<sbe::EVariable>(inputSlot), sbe::makeE<sbe::EConstant>(fieldName)))); diff --git a/src/mongo/db/query/sbe_stage_builder_helpers.cpp b/src/mongo/db/query/sbe_stage_builder_helpers.cpp index 86c5bad1eb2..31f214a9521 100644 --- a/src/mongo/db/query/sbe_stage_builder_helpers.cpp +++ b/src/mongo/db/query/sbe_stage_builder_helpers.cpp @@ -197,7 +197,7 @@ std::unique_ptr<sbe::PlanStage> makeLimitCoScanTree(PlanNodeId planNodeId, long std::unique_ptr<sbe::EExpression> makeFillEmptyFalse(std::unique_ptr<sbe::EExpression> e) { using namespace std::literals; - return makeFunction("fillEmpty"sv, + return makeFunction("fillEmpty"_sd, std::move(e), sbe::makeE<sbe::EConstant>(sbe::value::TypeTags::Boolean, sbe::value::bitcastFrom<bool>(false))); @@ -212,13 +212,13 @@ std::unique_ptr<sbe::EExpression> makeVariable(sbe::value::SlotId slotId, std::unique_ptr<sbe::EExpression> makeFillEmptyNull(std::unique_ptr<sbe::EExpression> e) { using namespace std::literals; return makeFunction( - "fillEmpty"sv, std::move(e), sbe::makeE<sbe::EConstant>(sbe::value::TypeTags::Null, 0)); + "fillEmpty"_sd, std::move(e), sbe::makeE<sbe::EConstant>(sbe::value::TypeTags::Null, 0)); } std::unique_ptr<sbe::EExpression> makeNothingArrayCheck( std::unique_ptr<sbe::EExpression> isArrayInput, std::unique_ptr<sbe::EExpression> otherwise) { using namespace std::literals; - return sbe::makeE<sbe::EIf>(makeFunction("isArray"sv, std::move(isArrayInput)), + return sbe::makeE<sbe::EIf>(makeFunction("isArray"_sd, std::move(isArrayInput)), sbe::makeE<sbe::EConstant>(sbe::value::TypeTags::Nothing, 0), std::move(otherwise)); } @@ -228,15 +228,11 @@ std::unique_ptr<sbe::EExpression> generateShardKeyBinding( sbe::value::FrameIdGenerator& frameIdGenerator, std::unique_ptr<sbe::EExpression> inputExpr, int level) { - using namespace std::literals; invariant(level >= 0); auto makeGetFieldKeyPattern = [&](std::unique_ptr<sbe::EExpression> slot) { - return makeFillEmptyNull( - makeFunction("getField"sv, std::move(slot), sbe::makeE<sbe::EConstant>([&]() { - const auto fieldName = keyPatternField[level]; - return std::string_view{fieldName.rawData(), fieldName.size()}; - }()))); + return makeFillEmptyNull(makeFunction( + "getField"_sd, std::move(slot), sbe::makeE<sbe::EConstant>(keyPatternField[level]))); }; if (level == keyPatternField.numParts() - 1) { @@ -531,7 +527,7 @@ std::pair<sbe::value::SlotVector, std::unique_ptr<sbe::PlanStage>> generateVirtu projectSlots.emplace_back(slotIdGenerator->generate()); projections.emplace( projectSlots.back(), - makeFunction("getElement"sv, + makeFunction("getElement"_sd, sbe::makeE<sbe::EVariable>(scanSlot), sbe::makeE<sbe::EConstant>(sbe::value::TypeTags::NumberInt32, sbe::value::bitcastFrom<int32_t>(i)))); diff --git a/src/mongo/db/query/sbe_stage_builder_helpers.h b/src/mongo/db/query/sbe_stage_builder_helpers.h index d5956b0ca8d..65b3371d034 100644 --- a/src/mongo/db/query/sbe_stage_builder_helpers.h +++ b/src/mongo/db/query/sbe_stage_builder_helpers.h @@ -188,7 +188,7 @@ std::unique_ptr<sbe::EExpression> makeFillEmptyFalse(std::unique_ptr<sbe::EExpre * Creates an EFunction expression with the given name and arguments. */ template <typename... Args> -inline std::unique_ptr<sbe::EExpression> makeFunction(std::string_view name, Args&&... args) { +inline std::unique_ptr<sbe::EExpression> makeFunction(StringData name, Args&&... args) { return sbe::makeE<sbe::EFunction>(name, sbe::makeEs(std::forward<Args>(args)...)); } @@ -197,7 +197,7 @@ inline auto makeConstant(sbe::value::TypeTags tag, T value) { return sbe::makeE<sbe::EConstant>(tag, sbe::value::bitcastFrom<T>(value)); } -inline auto makeConstant(std::string_view str) { +inline auto makeConstant(StringData str) { auto [tag, value] = sbe::value::makeNewString(str); return sbe::makeE<sbe::EConstant>(tag, value); } diff --git a/src/mongo/db/query/sbe_stage_builder_index_scan.cpp b/src/mongo/db/query/sbe_stage_builder_index_scan.cpp index 1eee1a968f7..84a20dfd9a4 100644 --- a/src/mongo/db/query/sbe_stage_builder_index_scan.cpp +++ b/src/mongo/db/query/sbe_stage_builder_index_scan.cpp @@ -301,10 +301,10 @@ generateOptimizedMultiIntervalIndexScan( for (auto&& [lowKey, highKey] : intervals) { auto [tag, val] = sbe::value::makeNewObject(); auto obj = sbe::value::getObjectView(val); - obj->push_back("l"sv, + obj->push_back("l"_sd, sbe::value::TypeTags::ksValue, sbe::value::bitcastFrom<KeyString::Value*>(lowKey.release())); - obj->push_back("h"sv, + obj->push_back("h"_sd, sbe::value::TypeTags::ksValue, sbe::value::bitcastFrom<KeyString::Value*>(highKey.release())); arr->push_back(tag, val); @@ -334,13 +334,13 @@ generateOptimizedMultiIntervalIndexScan( std::move(unwind), planNodeId, lowKeySlot, - sbe::makeE<sbe::EFunction>( - "getField"sv, - sbe::makeEs(sbe::makeE<sbe::EVariable>(unwindSlot), sbe::makeE<sbe::EConstant>("l"sv))), + sbe::makeE<sbe::EFunction>("getField"_sd, + sbe::makeEs(sbe::makeE<sbe::EVariable>(unwindSlot), + sbe::makeE<sbe::EConstant>("l"_sd))), highKeySlot, - sbe::makeE<sbe::EFunction>("getField"sv, + sbe::makeE<sbe::EFunction>("getField"_sd, sbe::makeEs(sbe::makeE<sbe::EVariable>(unwindSlot), - sbe::makeE<sbe::EConstant>("h"sv)))); + sbe::makeE<sbe::EConstant>("h"_sd)))); auto ixscan = sbe::makeS<sbe::IndexScanStage>(collection->uuid(), indexName, @@ -609,14 +609,14 @@ generateGenericMultiIntervalIndexScan(const CollectionPtr& collection, std::move(unionStage), spoolId, makeSlotVector(resultSlot, std::move(indexKeySlots)), - makeNot(makeFunction("isRecordId"sv, sbe::makeE<sbe::EVariable>(resultSlot))), + makeNot(makeFunction("isRecordId"_sd, sbe::makeE<sbe::EVariable>(resultSlot))), ixn->nodeId()); // Finally, add a filter stage on top to filter out seek keys and return only recordIds. return {resultSlot, sbe::makeS<sbe::FilterStage<false>>( std::move(spool), - sbe::makeE<sbe::EFunction>("isRecordId"sv, + sbe::makeE<sbe::EFunction>("isRecordId"_sd, sbe::makeEs(sbe::makeE<sbe::EVariable>(resultSlot))), ixn->nodeId())}; } diff --git a/src/mongo/db/query/sbe_stage_builder_projection.cpp b/src/mongo/db/query/sbe_stage_builder_projection.cpp index 896b36fba27..4bba27c9833 100644 --- a/src/mongo/db/query/sbe_stage_builder_projection.cpp +++ b/src/mongo/db/query/sbe_stage_builder_projection.cpp @@ -463,7 +463,7 @@ public: childLevelStage = sbe::makeS<sbe::FilterStage<true>>( std::move(mkBsonStage), - makeFunction("isObject"sv, sbe::makeE<sbe::EVariable>(childLevelInputSlot)), + makeFunction("isObject"_sd, sbe::makeE<sbe::EVariable>(childLevelInputSlot)), _context->planNodeId); } @@ -497,7 +497,7 @@ public: sbe::makeProjectStage(std::move(parentLevelStage), _context->planNodeId, childLevelInputSlot, - makeFunction("getField"sv, + makeFunction("getField"_sd, sbe::makeE<sbe::EVariable>(parentLevelInputSlot), makeConstant(_context->topFrontField()))); } @@ -603,8 +603,8 @@ public: auto isObjectOrArrayExpr = makeBinaryOp( sbe::EPrimBinary::logicOr, - makeFunction("isObject"sv, sbe::makeE<sbe::EVariable>(inputArraySlot)), - makeFunction("isArray"sv, sbe::makeE<sbe::EVariable>(inputArraySlot))); + makeFunction("isObject"_sd, sbe::makeE<sbe::EVariable>(inputArraySlot)), + makeFunction("isArray"_sd, sbe::makeE<sbe::EVariable>(inputArraySlot))); return sbe::makeS<sbe::FilterStage<true>>(std::move(elemMatchPredicateTree), std::move(isObjectOrArrayExpr), _context->planNodeId); @@ -680,7 +680,7 @@ public: std::move(_context->topLevel().evalStage), _context->planNodeId, inputArraySlot, - makeFunction("getField"sv, + makeFunction("getField"_sd, inputDocumentVariable.clone(), sbe::makeE<sbe::EConstant>(_context->topFrontField()))); @@ -688,7 +688,7 @@ public: std::move(fromBranch), _context->planNodeId, traversingAnArrayFlagSlot, - makeFunction("isArray"sv, sbe::makeE<sbe::EVariable>(inputArraySlot))); + makeFunction("isArray"_sd, sbe::makeE<sbe::EVariable>(inputArraySlot))); auto filteredArraySlot = _context->slotIdGenerator->generate(); auto traverseStage = @@ -813,7 +813,7 @@ public: childLevelStage = sbe::makeS<sbe::BranchStage>( std::move(childLevelStage), makeLimitCoScanTree(_context->planNodeId), - makeFunction("isObject"sv, sbe::makeE<sbe::EVariable>(childLevelInputSlot)), + makeFunction("isObject"_sd, sbe::makeE<sbe::EVariable>(childLevelInputSlot)), sbe::makeSV(childLevelObjSlot), sbe::makeSV(childLevelInputSlot), sbe::makeSV(childLevelResultSlot), @@ -831,7 +831,7 @@ public: sbe::makeProjectStage(std::move(parentLevelStage), _context->planNodeId, childLevelInputSlot, - makeFunction("getField"sv, + makeFunction("getField"_sd, sbe::makeE<sbe::EVariable>(parentLevelInputSlot), makeConstant(_context->topFrontField()))); } else { @@ -869,7 +869,7 @@ public: using namespace std::literals; auto arrayFromField = - makeFunction("getField"sv, + makeFunction("getField"_sd, sbe::makeE<sbe::EVariable>(_context->topLevel().inputSlot), makeConstant(_context->topFrontField())); auto binds = sbe::makeEs(std::move(arrayFromField)); @@ -884,7 +884,7 @@ public: } auto extractSubArrayExpr = sbe::makeE<sbe::EIf>( - makeFunction("isArray"sv, arrayVariable.clone()), + makeFunction("isArray"_sd, arrayVariable.clone()), sbe::makeE<sbe::EFunction>("extractSubArray", std::move(arguments)), arrayVariable.clone()); |