Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit 393fe9d

Browse files
BillyDonahueEvergreen Agent
authored andcommitted
SERVER-55180 Convert SBE from std::string_view to StringData
1 parent 17c5167 commit 393fe9d

34 files changed

+213
-275
lines changed

src/mongo/base/string_data.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ class StringData {
8989
*/
9090
StringData(const std::string& s) : StringData(s.data(), s.length(), TrustedInitTag()) {}
9191

92-
/**
93-
* Implicitly convert a std::string_view to a StringData. We can use the trusted
94-
* init path because string_view::data() points to length() bytes of data.
95-
*/
96-
StringData(std::string_view s) : StringData(s.data(), s.length(), TrustedInitTag()) {}
97-
9892
/**
9993
* Constructs a StringData with an explicit length. 'c' must
10094
* either be nullptr (in which case len must be zero), or be a
@@ -111,18 +105,6 @@ class StringData {
111105
return toString();
112106
}
113107

114-
/**
115-
* Implicitly convert to a std::string_view.
116-
*/
117-
operator std::string_view() const {
118-
// std::string_view produces undefined behaviour if [pointer, pointer + size) is not a valid
119-
// range. To fix this we explicitly use default constructor if StringData contains nullptr.
120-
if (MONGO_unlikely(rawData() == nullptr)) {
121-
return {};
122-
}
123-
return {rawData(), size()};
124-
}
125-
126108
/**
127109
* Constructs a StringData with begin and end iterators. begin points to the beginning of the
128110
* string. end points to the position past the end of the string. In a null-terminated string,

src/mongo/db/exec/sbe/expressions/expression.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ auto makeSV(Args&&... args) {
317317
class EConstant final : public EExpression {
318318
public:
319319
EConstant(value::TypeTags tag, value::Value val) : _tag(tag), _val(val) {}
320-
EConstant(std::string_view str) {
320+
EConstant(StringData str) {
321321
// Views are non-owning so we have to make a copy.
322322
std::tie(_tag, _val) = value::makeNewString(str);
323323
}
@@ -448,7 +448,7 @@ class EPrimUnary final : public EExpression {
448448
*/
449449
class EFunction final : public EExpression {
450450
public:
451-
EFunction(std::string_view name, std::vector<std::unique_ptr<EExpression>> args) : _name(name) {
451+
EFunction(StringData name, std::vector<std::unique_ptr<EExpression>> args) : _name(name) {
452452
_nodes = std::move(args);
453453
validateNodes();
454454
}
@@ -513,7 +513,7 @@ class ELocalBind final : public EExpression {
513513
*/
514514
class EFail final : public EExpression {
515515
public:
516-
EFail(ErrorCodes::Error code, std::string_view message) : _code(code) {
516+
EFail(ErrorCodes::Error code, StringData message) : _code(code) {
517517
std::tie(_messageTag, _messageVal) = value::makeNewString(message);
518518
}
519519

src/mongo/db/exec/sbe/expressions/sbe_concat_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
namespace mongo::sbe {
3434
class SBEConcatTest : public EExpressionTestFixture {
3535
protected:
36-
void runAndAssertExpression(const vm::CodeFragment* compiledExpr,
37-
std::string_view expectedVal) {
36+
void runAndAssertExpression(const vm::CodeFragment* compiledExpr, StringData expectedVal) {
3837
auto [tag, val] = runCompiledExpression(compiledExpr);
3938
value::ValueGuard guard(tag, val);
4039

src/mongo/db/exec/sbe/expressions/sbe_regex_test.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
namespace mongo::sbe {
3333
class SBERegexTest : public EExpressionTestFixture {
3434
protected:
35-
void runAndAssertRegexCompile(const vm::CodeFragment* compiledExpr,
36-
std::string_view regexString) {
35+
void runAndAssertRegexCompile(const vm::CodeFragment* compiledExpr, StringData regexString) {
3736
auto [tag, val] = runCompiledExpression(compiledExpr);
3837
value::ValueGuard guard(tag, val);
3938

@@ -53,7 +52,7 @@ class SBERegexTest : public EExpressionTestFixture {
5352
}
5453

5554
void runAndAssertFindExpression(const vm::CodeFragment* compiledExpr,
56-
std::string_view expectedMatch,
55+
StringData expectedMatch,
5756
int idx) {
5857
auto [tag, val] = runCompiledExpression(compiledExpr);
5958
value::ValueGuard guard(tag, val);
@@ -72,7 +71,7 @@ class SBERegexTest : public EExpressionTestFixture {
7271
ASSERT_EQUALS(value::numericCast<int32_t>(idxTag, idxVal), idx);
7372
}
7473

75-
void addMatchResult(value::Array* arrayPtr, std::string_view matchStr, int32_t idx) {
74+
void addMatchResult(value::Array* arrayPtr, StringData matchStr, int32_t idx) {
7675
auto [objTag, objVal] = value::makeNewObject();
7776
value::ValueGuard objGuard{objTag, objVal};
7877
auto obj = value::getObjectView(objVal);

src/mongo/db/exec/sbe/parser/parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ std::unique_ptr<PlanStage> Parser::walkPathValue(AstQuery& ast,
11611161
std::move(inputStage),
11621162
getCurrentPlanNodeId(),
11631163
outputSlot,
1164-
makeE<EFunction>("getField"sv,
1164+
makeE<EFunction>("getField"_sd,
11651165
makeEs(makeE<EVariable>(inputSlot),
11661166
makeE<EConstant>(ast.nodes[0]->identifier))));
11671167
}
@@ -1172,7 +1172,7 @@ std::unique_ptr<PlanStage> Parser::walkPathValue(AstQuery& ast,
11721172
makeProjectStage(std::move(inputStage),
11731173
getCurrentPlanNodeId(),
11741174
traverseIn,
1175-
makeE<EFunction>("getField"sv,
1175+
makeE<EFunction>("getField"_sd,
11761176
makeEs(makeE<EVariable>(inputSlot),
11771177
makeE<EConstant>(ast.nodes[0]->identifier))));
11781178
auto in = makeS<LimitSkipStage>(

src/mongo/db/exec/sbe/sbe_filter_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
#include "mongo/platform/basic.h"
3535

36-
#include <string_view>
3736

3837
#include "mongo/db/exec/sbe/sbe_plan_stage_test.h"
3938
#include "mongo/db/exec/sbe/stages/filter.h"
@@ -148,7 +147,7 @@ TEST_F(FilterStageTest, FilterIsNumberTest) {
148147
// Build a FilterStage whose filter expression is "isNumber(scanSlot)".
149148
auto filter = makeS<FilterStage<false>>(
150149
std::move(scanStage),
151-
makeE<EFunction>("isNumber"sv, makeEs(makeE<EVariable>(scanSlot))),
150+
makeE<EFunction>("isNumber"_sd, makeEs(makeE<EVariable>(scanSlot))),
152151
kEmptyPlanNodeId);
153152

154153
return std::make_pair(scanSlot, std::move(filter));

src/mongo/db/exec/sbe/sbe_hash_agg_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
#include "mongo/platform/basic.h"
3535

36-
#include <string_view>
3736

3837
#include "mongo/db/exec/sbe/sbe_plan_stage_test.h"
3938
#include "mongo/db/exec/sbe/stages/hash_agg.h"
@@ -115,7 +114,7 @@ TEST_F(HashAggStageTest, HashAggAddToSetTest) {
115114

116115
auto [expectedTag, expectedVal] = value::makeNewArray();
117116
value::ValueGuard expectedGuard{expectedTag, expectedVal};
118-
for (auto&& sv : std::array<std::string_view, 4>{"Aa", "BB", "cc", "dD"}) {
117+
for (auto&& sv : std::array<StringData, 4>{"Aa", "BB", "cc", "dD"}) {
119118
auto [tag, val] = value::makeNewString(sv);
120119
value::getArrayView(expectedVal)->push_back(tag, val);
121120
}

src/mongo/db/exec/sbe/sbe_hash_join_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
#include "mongo/platform/basic.h"
3535

36-
#include <string_view>
3736

3837
#include "mongo/db/exec/sbe/sbe_plan_stage_test.h"
3938
#include "mongo/db/exec/sbe/stages/hash_join.h"

src/mongo/db/exec/sbe/sbe_plan_stage_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
#include "mongo/db/exec/sbe/sbe_plan_stage_test.h"
3838

39-
#include <string_view>
4039

4140
#include "mongo/logv2/log.h"
4241

src/mongo/db/exec/sbe/sbe_sort_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
#include "mongo/platform/basic.h"
3131

32-
#include <string_view>
3332

3433
#include "mongo/db/exec/sbe/sbe_plan_stage_test.h"
3534
#include "mongo/db/exec/sbe/stages/sort.h"

0 commit comments

Comments
 (0)