| 498 | } |
| 499 | |
| 500 | void basic_string::shrink_to_fit() { |
| 501 | if (hasHeapData()) { |
| 502 | NotNullStringHolderPtr& heap = heapData(); |
| 503 | if (heap.get().use_count() > 1) return; |
| 504 | if (heap->capacity() <= mLength + 1) return; |
| 505 | if (mLength + 1 <= mInlineCapacity) { |
| 506 | fl::memcpy(inlineBufferPtr(), heap->data(), mLength + 1); |
| 507 | mStorage.reset(); |
| 508 | return; |
| 509 | } |
| 510 | NotNullStringHolderPtr newData = NotNullStringHolderPtr(fl::make_shared<StringHolder>(mLength)); |
| 511 | fl::memcpy(newData->data(), heap->data(), mLength + 1); |
| 512 | mStorage = newData; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | // ======= FIND ======= |
| 517 | |