Skip to content

Commit ea26ea2

Browse files
BillyDonahueMongoDB Bot
authored andcommitted
SERVER-105843 remove StringData.toString (#36937)
GitOrigin-RevId: e3d03a3ab4e1f6158a425e70ee4c4fc63af1313e
1 parent a852bee commit ea26ea2

File tree

487 files changed

+1361
-1366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

487 files changed

+1361
-1366
lines changed

buildscripts/idl/idl/cpp_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def get_transform_to_getter_type(self, expression):
251251

252252
def get_transform_to_storage_type(self, expression):
253253
# type: (str) -> Optional[str]
254-
return f"{expression}.toString()"
254+
return f"std::string{{{expression}}}"
255255

256256

257257
class _CppTypeVector(CppTypeBase):

buildscripts/idl/idl/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2961,7 +2961,7 @@ def _gen_doc_sequence_serializer(self, struct):
29612961
with self._block(optional_block_start, "}"):
29622962
self._writer.write_line("OpMsg::DocumentSequence documentSequence;")
29632963
self._writer.write_line(
2964-
f"documentSequence.name = {_get_field_constant_name(field)}.toString();"
2964+
f"documentSequence.name = std::string{{{_get_field_constant_name(field)}}};"
29652965
)
29662966

29672967
with self._block(f"for (const auto& item : {_access_member(field)}) {{", "}"):

src/mongo/base/data_type_terminated_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ TEST(DataTypeTerminated, StringDataNormalStore) {
115115
ASSERT_EQ(adv, w.size() + 1);
116116
ptr += adv;
117117
avail -= adv;
118-
expected += w.toString();
118+
expected += std::string{w};
119119
expected += '\0';
120120
}
121121
ASSERT_EQUALS(expected, buf.substr(0, buf.size() - avail));
@@ -125,7 +125,7 @@ TEST(DataTypeTerminated, StringDataNormalLoad) {
125125
const StringData writes[] = {StringData("a"), StringData("bb"), StringData("ccc")};
126126
std::string buf;
127127
for (const auto& w : writes) {
128-
buf += w.toString();
128+
buf += std::string{w};
129129
buf += '\0';
130130
}
131131
const char* const bufBegin = &*buf.begin();

src/mongo/base/parse_number.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ Status parseNumberFromStringHelper<double>(StringData stringValue,
229229
if (!parser._skipLeadingWhitespace && ctype::isSpace(stringValue[0]))
230230
return Status(ErrorCodes::FailedToParse, "Leading whitespace");
231231

232-
std::string str = stringValue.toString();
232+
std::string str = std::string{stringValue};
233233
const char* cStr = str.c_str();
234234
char* endp;
235235
errno = 0;
@@ -298,7 +298,7 @@ Status parseNumberFromStringHelper<Decimal128>(StringData stringValue,
298298
std::uint32_t signalingFlags = 0;
299299
size_t charsConsumed;
300300
auto parsedDecimal =
301-
Decimal128(stringValue.toString(), &signalingFlags, parser._roundingMode, &charsConsumed);
301+
Decimal128(std::string{stringValue}, &signalingFlags, parser._roundingMode, &charsConsumed);
302302

303303
if (Decimal128::hasFlag(signalingFlags, Decimal128::SignalingFlag::kOverflow)) {
304304
return Status(ErrorCodes::Overflow, "Conversion from string to decimal would overflow");

src/mongo/base/parse_number_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ PARSE_TEST(TestSkipLeadingWhitespace) {
290290
}
291291

292292
for (StringData ws : whitespaces) {
293-
std::string withWhitespace = ws.toString() + numStr;
293+
std::string withWhitespace = std::string{ws} + numStr;
294294
if (shouldParse) {
295295
ASSERT_PARSES_WITH_PARSER(NumberType, withWhitespace, skipWs, expected);
296296
} else {
@@ -338,7 +338,7 @@ PARSE_TEST(TestEndOfNum) {
338338
ASSERT_EQ(ErrorCodes::FailedToParse, parsed);
339339
}
340340
for (StringData& suffix : suffixes) {
341-
std::string spec = numStr.toString() + suffix;
341+
std::string spec = std::string{numStr} + suffix;
342342
char* numEnd = nullptr;
343343
NumberType actual;
344344
parsed = NumberParser().allowTrailingText()(spec, &actual, &numEnd);
@@ -400,7 +400,7 @@ PARSE_TEST(TestSkipLeadingWsAndEndptr) {
400400
ASSERT_EQ(ErrorCodes::FailedToParse, parsed);
401401
}
402402
for (StringData& prefix : whitespaces) {
403-
std::string spec = prefix.toString() + numStr;
403+
std::string spec = std::string{prefix} + numStr;
404404
char* numEnd = nullptr;
405405
NumberType actual;
406406
parsed = NumberParser().skipWhitespace()(spec, &actual, &numEnd);

src/mongo/base/string_data.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,6 @@ class MONGO_GSL_POINTER StringData {
309309
STRING_DATA_DEFINE_FIND_OVERLOADS_(find_last_not_of, npos)
310310
#undef STRING_DATA_FIND_OVERLOADS_
311311

312-
/** Deprecated: Use an explicit cast instead: `sd.toString()` => `std::string{sd}` */
313-
std::string toString() const {
314-
return std::string{_sv};
315-
}
316-
317312
friend constexpr auto operator<=>(StringData a, StringData b) = default;
318313
friend constexpr bool operator==(StringData a, StringData b) = default;
319314

src/mongo/base/string_data_test.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ TEST(Construction, FromStdString) {
5858
std::string base("aaa");
5959
StringData strData(base);
6060
ASSERT_EQUALS(strData.size(), base.size());
61-
ASSERT_EQUALS(strData.toString(), base);
61+
ASSERT_EQUALS(std::string{strData}, base);
6262
}
6363

6464
TEST(Construction, FromCString) {
6565
std::string base("aaa");
6666
StringData strData(base.c_str());
6767
ASSERT_EQUALS(strData.size(), base.size());
68-
ASSERT_EQUALS(strData.toString(), base);
68+
ASSERT_EQUALS(std::string{strData}, base);
6969
}
7070

7171
TEST(Construction, FromNullCString) {
@@ -78,19 +78,19 @@ TEST(Construction, FromNullCString) {
7878
TEST(Construction, FromUserDefinedLiteral) {
7979
const auto strData = "cc\0c"_sd;
8080
ASSERT_EQUALS(strData.size(), 4U);
81-
ASSERT_EQUALS(strData.toString(), std::string("cc\0c", 4));
81+
ASSERT_EQUALS(std::string{strData}, std::string("cc\0c", 4));
8282
}
8383

8484
TEST(Construction, FromUserDefinedRawLiteral) {
8585
const auto strData = R"("")"_sd;
8686
ASSERT_EQUALS(strData.size(), 2U);
87-
ASSERT_EQUALS(strData.toString(), std::string("\"\"", 2));
87+
ASSERT_EQUALS(std::string{strData}, std::string("\"\"", 2));
8888
}
8989

9090
TEST(Construction, FromEmptyUserDefinedLiteral) {
9191
const auto strData = ""_sd;
9292
ASSERT_EQUALS(strData.size(), 0U);
93-
ASSERT_EQUALS(strData.toString(), std::string(""));
93+
ASSERT_EQUALS(std::string{strData}, std::string(""));
9494
}
9595

9696
// Try some constexpr initializations
@@ -296,21 +296,22 @@ TEST(Rfind, Char1) {
296296

297297
// this is to verify we match std::string
298298
void SUBSTR_TEST_HELP(StringData big, StringData small, size_t start, size_t len) {
299-
ASSERT_EQUALS(small.toString(), big.toString().substr(start, len));
299+
ASSERT_EQUALS(std::string{small}, std::string{big}.substr(start, len));
300300
ASSERT_EQUALS(small, StringData(big).substr(start, len));
301301
}
302302
void SUBSTR_TEST_HELP(StringData big, StringData small, size_t start) {
303-
ASSERT_EQUALS(small.toString(), big.toString().substr(start));
303+
ASSERT_EQUALS(std::string{small}, std::string{big}.substr(start));
304304
ASSERT_EQUALS(small, StringData(big).substr(start));
305305
}
306306

307307
// [12] is number of args to substr
308-
#define SUBSTR_1_TEST_HELP(big, small, start) \
309-
ASSERT_EQUALS(StringData(small).toString(), StringData(big).toString().substr(start)); \
308+
#define SUBSTR_1_TEST_HELP(big, small, start) \
309+
ASSERT_EQUALS(std::string{StringData(small)}, std::string{StringData(big)}.substr(start)); \
310310
ASSERT_EQUALS(StringData(small), StringData(big).substr(start));
311311

312-
#define SUBSTR_2_TEST_HELP(big, small, start, len) \
313-
ASSERT_EQUALS(StringData(small).toString(), StringData(big).toString().substr(start, len)); \
312+
#define SUBSTR_2_TEST_HELP(big, small, start, len) \
313+
ASSERT_EQUALS(std::string{StringData(small)}, \
314+
std::string{StringData(big)}.substr(start, len)); \
314315
ASSERT_EQUALS(StringData(small), StringData(big).substr(start, len));
315316

316317
TEST(Substr, Simple1) {

src/mongo/bson/bsonelement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ std::string BSONElement::_asCode() const {
799799
switch (type()) {
800800
case BSONType::string:
801801
case BSONType::code:
802-
return valueStringData().toString();
802+
return std::string{valueStringData()};
803803
case BSONType::codeWScope:
804804
return std::string(codeWScopeCode(),
805805
ConstDataView(valuestr()).read<LittleEndian<int>>() - 1);

src/mongo/bson/bsonelement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ class BSONElement {
603603
* Like valueStringDataSafe, but returns std::string.
604604
*/
605605
std::string str() const {
606-
return valueStringDataSafe().toString();
606+
return std::string{valueStringDataSafe()};
607607
}
608608

609609
/**

src/mongo/bson/util/bson_extract.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Status bsonExtractFieldImpl(const BSONObj& object,
5656
return kDefaultCase;
5757
}
5858
return Status(ErrorCodes::NoSuchKey,
59-
str::stream() << "Missing expected field \"" << fieldName.toString() << "\"");
59+
str::stream() << "Missing expected field \"" << std::string{fieldName} << "\"");
6060
}
6161

6262
Status bsonExtractTypedFieldImpl(const BSONObj& object,
@@ -210,7 +210,7 @@ Status bsonExtractStringFieldWithDefault(const BSONObj& object,
210210
BSONElement element;
211211
Status status = bsonExtractTypedFieldImpl(object, fieldName, BSONType::string, &element, true);
212212
if (status == ErrorCodes::NoSuchKey) {
213-
*out = defaultValue.toString();
213+
*out = std::string{defaultValue};
214214
return Status::OK();
215215
}
216216
if (status.isOK())

0 commit comments

Comments
 (0)