| 85 | } |
| 86 | |
| 87 | const char* PagedInputStream::ensureInput(size_t availableInputBytes) { |
| 88 | auto input = inputBufferPtr_; |
| 89 | if (remainingLength_ <= availableInputBytes) { |
| 90 | inputBufferPtr_ += availableInputBytes; |
| 91 | return input; |
| 92 | } |
| 93 | // make sure input buffer has capacity |
| 94 | if (inputBuffer_.capacity() < remainingLength_) { |
| 95 | inputBuffer_.reserve(remainingLength_); |
| 96 | } |
| 97 | |
| 98 | std::copy( |
| 99 | inputBufferPtr_, |
| 100 | inputBufferPtr_ + availableInputBytes, |
| 101 | inputBuffer_.data()); |
| 102 | inputBufferPtr_ += availableInputBytes; |
| 103 | |
| 104 | for (size_t pos = availableInputBytes; pos < remainingLength_;) { |
| 105 | readBuffer(true); |
| 106 | availableInputBytes = std::min( |
| 107 | static_cast<size_t>(inputBufferPtrEnd_ - inputBufferPtr_), |
| 108 | remainingLength_ - pos); |
| 109 | std::copy( |
| 110 | inputBufferPtr_, |
| 111 | inputBufferPtr_ + availableInputBytes, |
| 112 | inputBuffer_.data() + pos); |
| 113 | pos += availableInputBytes; |
| 114 | inputBufferPtr_ += availableInputBytes; |
| 115 | } |
| 116 | return inputBuffer_.data(); |
| 117 | } |
| 118 | |
| 119 | bool PagedInputStream::Next(const void** data, int32_t* size) { |
| 120 | BOLT_CHECK_NOT_NULL(data); |