From fde26c53f0dcb67ec1f954fd24a26cbfc0c428d5 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Mon, 7 Aug 2023 22:40:34 -0400 Subject: [PATCH] AK: Remove the API to explicitly construct short strings Now that ""_string is infallible, the only benefit of explicitly constructing a short string is the ability to do it at compile-time. But we never do that, so let's simplify the API and remove this implementation detail from it. --- AK/String.h | 20 -------------------- Tests/AK/TestString.cpp | 23 ++--------------------- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/AK/String.h b/AK/String.h index e60b174c34..d017ef3714 100644 --- a/AK/String.h +++ b/AK/String.h @@ -73,21 +73,6 @@ public: // Creates a new String by reading byte_count bytes from a UTF-8 encoded Stream. static ErrorOr from_stream(Stream&, size_t byte_count); - // Creates a new String from a short sequence of UTF-8 encoded code points. If the provided string - // does not fit in the short string storage, a compilation error will be emitted. - static AK_SHORT_STRING_CONSTEVAL String from_utf8_short_string(StringView string) - { - VERIFY(string.length() <= MAX_SHORT_STRING_BYTE_COUNT); - VERIFY(Utf8View { string }.validate()); - - ShortString short_string; - for (size_t i = 0; i < string.length(); ++i) - short_string.storage[i] = string.characters_without_null_termination()[i]; - short_string.byte_count_and_short_string_flag = (string.length() << 1) | SHORT_STRING_FLAG; - - return String { short_string }; - } - // Creates a new String from a single code point. static constexpr String from_code_point(u32 code_point) { @@ -284,8 +269,3 @@ struct Formatter : Formatter { { return AK::String::from_utf8(AK::StringView(cstring, length)).release_value(); } - -[[nodiscard]] ALWAYS_INLINE AK_SHORT_STRING_CONSTEVAL AK::String operator""_short_string(char const* cstring, size_t length) -{ - return AK::String::from_utf8_short_string(AK::StringView(cstring, length)); -} diff --git a/Tests/AK/TestString.cpp b/Tests/AK/TestString.cpp index c2f3d631c1..02514c1c92 100644 --- a/Tests/AK/TestString.cpp +++ b/Tests/AK/TestString.cpp @@ -47,40 +47,21 @@ TEST_CASE(short_strings) EXPECT_EQ(string1.bytes().size(), 7u); EXPECT_EQ(string1.bytes_as_string_view(), "abcdefg"sv); - constexpr auto string2 = String::from_utf8_short_string("abcdefg"sv); + auto string2 = "abcdefg"_string; EXPECT_EQ(string2.is_short_string(), true); EXPECT_EQ(string2.bytes().size(), 7u); EXPECT_EQ(string2, string1); - auto string3 = "abcdefg"_string; - EXPECT_EQ(string3.is_short_string(), true); - EXPECT_EQ(string3.bytes().size(), 7u); - EXPECT_EQ(string3, string1); - - constexpr auto string4 = "abcdefg"_short_string; - EXPECT_EQ(string4.is_short_string(), true); - EXPECT_EQ(string4.bytes().size(), 7u); - EXPECT_EQ(string4, string1); #else auto string1 = MUST(String::from_utf8("abc"sv)); EXPECT_EQ(string1.is_short_string(), true); EXPECT_EQ(string1.bytes().size(), 3u); EXPECT_EQ(string1.bytes_as_string_view(), "abc"sv); - constexpr auto string2 = String::from_utf8_short_string("abc"sv); + auto string2 = "abc"_string; EXPECT_EQ(string2.is_short_string(), true); EXPECT_EQ(string2.bytes().size(), 3u); EXPECT_EQ(string2, string1); - - auto string3 = "abc"_string; - EXPECT_EQ(string3.is_short_string(), true); - EXPECT_EQ(string3.bytes().size(), 3u); - EXPECT_EQ(string3, string1); - - constexpr auto string4 = "abc"_short_string; - EXPECT_EQ(string4.is_short_string(), true); - EXPECT_EQ(string4.bytes().size(), 3u); - EXPECT_EQ(string4, string1); #endif }