| 358 | |
| 359 | template <typename T, std::size_t SIZE, typename Allocator> |
| 360 | void MemoryBuffer<T, SIZE, Allocator>::grow(std::size_t size) { |
| 361 | std::size_t new_capacity = |
| 362 | (std::max)(size, this->capacity_ + this->capacity_ / 2); |
| 363 | T *new_ptr = this->allocate(new_capacity); |
| 364 | // The following code doesn't throw, so the raw pointer above doesn't leak. |
| 365 | std::copy(this->ptr_, |
| 366 | this->ptr_ + this->size_, make_ptr(new_ptr, new_capacity)); |
| 367 | std::size_t old_capacity = this->capacity_; |
| 368 | T *old_ptr = this->ptr_; |
| 369 | this->capacity_ = new_capacity; |
| 370 | this->ptr_ = new_ptr; |
| 371 | // deallocate may throw (at least in principle), but it doesn't matter since |
| 372 | // the buffer already uses the new storage and will deallocate it in case |
| 373 | // of exception. |
| 374 | if (old_ptr != data_) |
| 375 | this->deallocate(old_ptr, old_capacity); |
| 376 | } |
| 377 | |
| 378 | #ifndef _MSC_VER |
| 379 | // Portable version of signbit. |
nothing calls this directly
no test coverage detected