Skip to content

Commit

Permalink
YT-22593: More trivial TString->std::string migrations
Browse files Browse the repository at this point in the history
[nodiff:runtime]
commit_hash:1ba799aed1703ab7c6304b6da7090b3337f768dd
  • Loading branch information
babenko committed Feb 22, 2025
1 parent 31f62e9 commit 4538383
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ TYPED_TEST(CompactVectorTest, InsertEnd)
{
SCOPED_TRACE("InsertEnd");

TCompactVector<TString, 5> vector;
TCompactVector<std::string, 5> vector;
for (int index = 0; index < 10; ++index) {
vector.insert(vector.end(), ToString(index));
}
Expand All @@ -286,7 +286,7 @@ TYPED_TEST(CompactVectorTest, ShrinkToSmall)
{
SCOPED_TRACE("ShrinkToSmall");

TCompactVector<TString, 5> vector;
TCompactVector<std::string, 5> vector;
for (int index = 0; index < 10; ++index) {
vector.shrink_to_small();
vector.push_back(ToString(index));
Expand Down Expand Up @@ -1061,19 +1061,19 @@ TEST(CompactVectorTest, InitializerList) {
}

TEST(CompactVectorTest, AssignToShorter) {
TCompactVector<TString, 4> lhs;
TCompactVector<TString, 4> rhs;
TCompactVector<std::string, 4> lhs;
TCompactVector<std::string, 4> rhs;
rhs.emplace_back("foo");
lhs = rhs;
EXPECT_EQ(1U, lhs.size());
EXPECT_EQ("foo", lhs[0]);
}

TEST(CompactVectorTest, AssignToLonger) {
TCompactVector<TString, 4> lhs;
TCompactVector<std::string, 4> lhs;
lhs.emplace_back("bar");
lhs.emplace_back("baz");
TCompactVector<TString, 4> rhs;
TCompactVector<std::string, 4> rhs;
rhs.emplace_back("foo");
lhs = rhs;
EXPECT_EQ(1U, lhs.size());
Expand Down
6 changes: 3 additions & 3 deletions library/cpp/yt/exception/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ void AddAttributes(TSimpleException::TAttributes& attrs, TRange&& range)

////////////////////////////////////////////////////////////////////////////////

TSimpleException::TSimpleException(TString message)
TSimpleException::TSimpleException(std::string message)
: Message_(std::move(message))
, What_(Message_)
{ }

TSimpleException::TSimpleException(
const std::exception& exception,
TString message)
std::string message)
: InnerException_(std::current_exception())
, Message_(std::move(message))
, What_(Message_ + "\n" + exception.what())
Expand All @@ -43,7 +43,7 @@ const char* TSimpleException::what() const noexcept
return What_.c_str();
}

const TString& TSimpleException::GetMessage() const
const std::string& TSimpleException::GetMessage() const
{
return Message_;
}
Expand Down
10 changes: 5 additions & 5 deletions library/cpp/yt/exception/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class TSimpleException
{ ex <<= std::forward<TValue>(operand) } -> std::same_as<TSimpleException&>;
};

explicit TSimpleException(TString message);
explicit TSimpleException(std::string message);
TSimpleException(
const std::exception& exception,
TString message);
std::string message);

const std::exception_ptr& GetInnerException() const;
const char* what() const noexcept override;

const TString& GetMessage() const;
const std::string& GetMessage() const;

const TAttributes& GetAttributes() const &;
TAttributes&& GetAttributes() &&;
Expand Down Expand Up @@ -65,8 +65,8 @@ class TSimpleException

private:
const std::exception_ptr InnerException_;
const TString Message_;
const TString What_;
const std::string Message_;
const std::string What_;

TAttributes Attributes_;
};
Expand Down
4 changes: 2 additions & 2 deletions library/cpp/yt/misc/guid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TGuid TGuid::FromString(TStringBuf str)
TGuid guid;
if (!FromString(str, &guid)) {
throw TSimpleException(Sprintf("Error parsing GUID \"%s\"",
TString(str).c_str()));
std::string(str).c_str()));
}
return guid;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ TGuid TGuid::FromStringHex32(TStringBuf str)
TGuid guid;
if (!FromStringHex32(str, &guid)) {
throw TSimpleException(Sprintf("Error parsing Hex32 GUID \"%s\"",
TString(str).c_str()));
str.data()));
}
return guid;
}
Expand Down
2 changes: 1 addition & 1 deletion library/cpp/yt/misc/thread_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TStringBuf TThreadName::ToStringBuf() const

////////////////////////////////////////////////////////////////////////////////

TThreadName::TThreadName(const TString& name)
TThreadName::TThreadName(TStringBuf name)
{
Length = std::min<int>(TThreadName::BufferCapacity - 1, name.length());
::memcpy(Buffer.data(), name.data(), Length);
Expand Down
2 changes: 1 addition & 1 deletion library/cpp/yt/misc/thread_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace NYT {
struct TThreadName
{
TThreadName() = default;
TThreadName(const TString& name);
TThreadName(TStringBuf name);

TStringBuf ToStringBuf() const;

Expand Down
2 changes: 1 addition & 1 deletion library/cpp/yt/string/enum-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void FormatEnum(TStringBuilderBase* builder, T value, bool lowerCase)
}

template <class T>
TString FormatEnum(T value)
std::string FormatEnum(T value)
{
TStringBuilder builder;
FormatEnum(&builder, value, /*lowerCase*/ true);
Expand Down
8 changes: 4 additions & 4 deletions library/cpp/yt/string/enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void ThrowMalformedEnumValueException(TStringBuf typeName, TStringBuf value)
}

template <bool ThrowOnError>
std::optional<TString> DecodeEnumValueImpl(TStringBuf value)
std::optional<std::string> DecodeEnumValueImpl(TStringBuf value)
{
auto camelValue = UnderscoreCaseToCamelCase(value);
auto underscoreValue = CamelCaseToUnderscoreCase(camelValue);
Expand All @@ -34,19 +34,19 @@ std::optional<TString> DecodeEnumValueImpl(TStringBuf value)

} // namespace NDetail

std::optional<TString> TryDecodeEnumValue(TStringBuf value)
std::optional<std::string> TryDecodeEnumValue(TStringBuf value)
{
return NDetail::DecodeEnumValueImpl<false>(value);
}

TString DecodeEnumValue(TStringBuf value)
std::string DecodeEnumValue(TStringBuf value)
{
auto decodedValue = NDetail::DecodeEnumValueImpl<true>(value);
YT_VERIFY(decodedValue);
return *decodedValue;
}

TString EncodeEnumValue(TStringBuf value)
std::string EncodeEnumValue(TStringBuf value)
{
return CamelCaseToUnderscoreCase(value);
}
Expand Down
8 changes: 4 additions & 4 deletions library/cpp/yt/string/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace NYT {

////////////////////////////////////////////////////////////////////////////////

std::optional<TString> TryDecodeEnumValue(TStringBuf value);
TString DecodeEnumValue(TStringBuf value);
TString EncodeEnumValue(TStringBuf value);
std::optional<std::string> TryDecodeEnumValue(TStringBuf value);
std::string DecodeEnumValue(TStringBuf value);
std::string EncodeEnumValue(TStringBuf value);

template <class T>
std::optional<T> TryParseEnum(TStringBuf str, bool enableUnknown = false);
Expand All @@ -24,7 +24,7 @@ template <class T>
void FormatEnum(TStringBuilderBase* builder, T value, bool lowerCase);

template <class T>
TString FormatEnum(T value);
std::string FormatEnum(T value);

////////////////////////////////////////////////////////////////////////////////

Expand Down
4 changes: 2 additions & 2 deletions library/cpp/yt/string/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ TStringBuf FormatBool(bool value)

////////////////////////////////////////////////////////////////////////////////

void TruncateStringInplace(TString* string, int lengthLimit, TStringBuf truncatedSuffix)
void TruncateStringInplace(std::string* string, int lengthLimit, TStringBuf truncatedSuffix)
{
if (std::ssize(*string) > lengthLimit) {
string->resize(lengthLimit);
string->append(truncatedSuffix);
}
}

TString TruncateString(TString string, int lengthLimit, TStringBuf truncatedSuffix)
std::string TruncateString(std::string string, int lengthLimit, TStringBuf truncatedSuffix)
{
TruncateStringInplace(&string, lengthLimit, truncatedSuffix);
return string;
Expand Down
5 changes: 2 additions & 3 deletions library/cpp/yt/string/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,8 @@ TStringBuf FormatBool(bool value);

inline constexpr TStringBuf DefaultTruncatedMessage = "...<truncated>";

void TruncateStringInplace(TString* string, int lengthLimit, TStringBuf truncatedSuffix = DefaultTruncatedMessage);

TString TruncateString(TString string, int lengthLimit, TStringBuf truncatedSuffix = DefaultTruncatedMessage);
void TruncateStringInplace(std::string* string, int lengthLimit, TStringBuf truncatedSuffix = DefaultTruncatedMessage);
std::string TruncateString(std::string string, int lengthLimit, TStringBuf truncatedSuffix = DefaultTruncatedMessage);

////////////////////////////////////////////////////////////////////////////////

Expand Down

0 comments on commit 4538383

Please sign in to comment.