| 127 | } |
| 128 | |
| 129 | ASMJIT_FAVOR_SIZE Error StringBuilder::reserve(size_t to) noexcept { |
| 130 | if (_capacity >= to) |
| 131 | return kErrorOk; |
| 132 | |
| 133 | if (to >= IntTraits<size_t>::maxValue() - sizeof(intptr_t) * 2) |
| 134 | return DebugUtils::errored(kErrorNoHeapMemory); |
| 135 | |
| 136 | to = Utils::alignTo<size_t>(to, sizeof(intptr_t)); |
| 137 | char* newData = static_cast<char*>(Internal::allocMemory(to + sizeof(intptr_t))); |
| 138 | |
| 139 | if (!newData) |
| 140 | return DebugUtils::errored(kErrorNoHeapMemory); |
| 141 | |
| 142 | ::memcpy(newData, _data, _length + 1); |
| 143 | if (_canFree) |
| 144 | Internal::releaseMemory(_data); |
| 145 | |
| 146 | _data = newData; |
| 147 | _capacity = to + sizeof(intptr_t) - 1; |
| 148 | _canFree = true; |
| 149 | return kErrorOk; |
| 150 | } |
| 151 | |
| 152 | // ============================================================================ |
| 153 | // [asmjit::StringBuilder - Clear] |
no test coverage detected