Explorar o código

AK: Change String's default constructor to be constant

This allows creating expressions such as:

    constexpr Array<String, 10> {};
Timothy Flynn %!s(int64=2) %!d(string=hai) anos
pai
achega
8aca8e82cb
Modificáronse 2 ficheiros con 4 adicións e 7 borrados
  1. 0 6
      AK/String.cpp
  2. 4 1
      AK/String.h

+ 0 - 6
AK/String.cpp

@@ -208,12 +208,6 @@ void String::destroy_string()
         m_data->unref();
         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)
 ErrorOr<String> String::from_utf8(StringView view)
 {
 {
     if (view.length() <= MAX_SHORT_STRING_BYTE_COUNT) {
     if (view.length() <= MAX_SHORT_STRING_BYTE_COUNT) {

+ 4 - 1
AK/String.h

@@ -52,7 +52,10 @@ public:
     }
     }
 
 
     // Creates an empty (zero-length) String.
     // 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.
     // Creates a new String from a sequence of UTF-8 encoded code points.
     static ErrorOr<String> from_utf8(StringView);
     static ErrorOr<String> from_utf8(StringView);