| 161 | } |
| 162 | |
| 163 | void basic_string::materialize() { |
| 164 | if (mStorage.is<ConstLiteral>()) { |
| 165 | const char* data = mStorage.get<ConstLiteral>().data; |
| 166 | if (!data) { |
| 167 | mLength = 0; |
| 168 | mStorage.reset(); |
| 169 | inlineBufferPtr()[0] = '\0'; |
| 170 | return; |
| 171 | } |
| 172 | fl::size len = mLength; |
| 173 | if (len + 1 <= mInlineCapacity) { |
| 174 | fl::memcpy(inlineBufferPtr(), data, len); |
| 175 | inlineBufferPtr()[len] = '\0'; |
| 176 | mStorage.reset(); |
| 177 | } else { |
| 178 | mStorage = NotNullStringHolderPtr(fl::make_shared<StringHolder>(data, len)); |
| 179 | } |
| 180 | } else if (mStorage.is<ConstView>()) { |
| 181 | const ConstView& view = mStorage.get<ConstView>(); |
| 182 | if (!view.data) { |
| 183 | mLength = 0; |
| 184 | mStorage.reset(); |
| 185 | inlineBufferPtr()[0] = '\0'; |
| 186 | return; |
| 187 | } |
| 188 | fl::size len = view.length; |
| 189 | mLength = len; |
| 190 | if (len + 1 <= mInlineCapacity) { |
| 191 | fl::memcpy(inlineBufferPtr(), view.data, len); |
| 192 | inlineBufferPtr()[len] = '\0'; |
| 193 | mStorage.reset(); |
| 194 | } else { |
| 195 | mStorage = NotNullStringHolderPtr(fl::make_shared<StringHolder>(view.data, len)); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | NotNullStringHolderPtr& basic_string::heapData() { |
| 201 | if (!mStorage.is<NotNullStringHolderPtr>()) { |