| 95 | |
| 96 | template <class Storage, class CharType> |
| 97 | void |
| 98 | ByteStreamHandleBuf<Storage, CharType, Mutable>::resize( |
| 99 | size_t inSize, size_t inPivot) { |
| 100 | |
| 101 | if (inSize == this->size()) |
| 102 | return; |
| 103 | |
| 104 | char_type* oldPtr = this->ptr(); |
| 105 | size_t secondChunkStart |
| 106 | = inPivot > this->size() ? this->size() : inPivot; |
| 107 | size_t oldSize = this->size(); |
| 108 | ptrdiff_t delta = inSize - oldSize; |
| 109 | |
| 110 | // FIXME: Deallocate old memory! |
| 111 | this->mStorage = defaultAllocator().allocateByteString< |
| 112 | dbal::FunctionContext, dbal::DoZero, dbal::ThrowBadAlloc>(inSize); |
| 113 | |
| 114 | std::copy(oldPtr, oldPtr + secondChunkStart, this->ptr()); |
| 115 | std::copy(oldPtr + secondChunkStart, oldPtr + oldSize, |
| 116 | this->ptr() + secondChunkStart + delta); |
| 117 | std::fill(this->ptr() + secondChunkStart, |
| 118 | this->ptr() + secondChunkStart + delta, 0); |
| 119 | } |
| 120 | |
| 121 | } // namespace dbal |
| 122 | |