diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-21 12:02:49 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-22 01:03:13 +0000 |
commit | 8aca8e82cbaefc92f7622e8f793c95aa7d07411f (patch) | |
tree | d131e02761880e979a052e3a01a7e4d1e3a03a17 | |
parent | 34574c5ee8ba634bee6d1f4e40ca7422097d9f6c (diff) | |
download | serenity-8aca8e82cbaefc92f7622e8f793c95aa7d07411f.zip |
AK: Change String's default constructor to be constant
This allows creating expressions such as:
constexpr Array<String, 10> {};
-rw-r--r-- | AK/String.cpp | 6 | ||||
-rw-r--r-- | AK/String.h | 5 |
2 files changed, 4 insertions, 7 deletions
diff --git a/AK/String.cpp b/AK/String.cpp index 1924aef113..6fe7f9af52 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -208,12 +208,6 @@ void String::destroy_string() m_data->unref(); } -String::String() -{ - // This is an empty string, it's always short and zero-length. - m_short_string.byte_count_and_short_string_flag = SHORT_STRING_FLAG; -} - ErrorOr<String> String::from_utf8(StringView view) { if (view.length() <= MAX_SHORT_STRING_BYTE_COUNT) { diff --git a/AK/String.h b/AK/String.h index c5a22111a0..dc73fe7d55 100644 --- a/AK/String.h +++ b/AK/String.h @@ -52,7 +52,10 @@ public: } // Creates an empty (zero-length) String. - String(); + constexpr String() + : String(ShortString { SHORT_STRING_FLAG, {} }) + { + } // Creates a new String from a sequence of UTF-8 encoded code points. static ErrorOr<String> from_utf8(StringView); |