diff options
-rw-r--r-- | common/stream.cpp | 17 | ||||
-rw-r--r-- | common/stream.h | 14 |
2 files changed, 18 insertions, 13 deletions
diff --git a/common/stream.cpp b/common/stream.cpp index 9f8f6127f1..0e8e578e86 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -331,7 +331,8 @@ BufferedWriteStream::BufferedWriteStream(WriteStream *parentStream, uint32 bufSi } BufferedWriteStream::~BufferedWriteStream() { - assert(flush()); + const bool flushResult = flushBuffer(); + assert(flushResult); if (_disposeParentStream) delete _parentStream; @@ -345,20 +346,20 @@ uint32 BufferedWriteStream::write(const void *dataPtr, uint32 dataSize) { memcpy(_buf + _pos, dataPtr, dataSize); _pos += dataSize; } else if (_bufSize >= dataSize) { // check if we can flush the buffer and load the data - // flush the buffer - assert(flushBuffer()); + const bool flushResult = flushBuffer(); + assert(flushResult); memcpy(_buf, dataPtr, dataSize); _pos += dataSize; } else { // too big for our buffer - // flush the buffer - assert(flushBuffer()); + const bool flushResult = flushBuffer(); + assert(flushResult); return _parentStream->write(dataPtr, dataSize); } return dataSize; } bool BufferedWriteStream::flushBuffer() { - uint32 bytesToWrite = _pos; + const uint32 bytesToWrite = _pos; if (bytesToWrite) { _pos = 0; @@ -368,10 +369,6 @@ bool BufferedWriteStream::flushBuffer() { return true; } -bool BufferedWriteStream::flush() { - return flushBuffer(); -} - bool MemoryWriteStreamDynamic::seek(int32 offs, int whence) { // Pre-Condition assert(_pos <= _size); diff --git a/common/stream.h b/common/stream.h index c6605cb42d..d497cabe2b 100644 --- a/common/stream.h +++ b/common/stream.h @@ -534,15 +534,23 @@ protected: DisposeAfterUse::Flag _disposeParentStream; byte *_buf; uint32 _pos; - uint32 _bufSize; - bool flushBuffer(); // write out the data in the buffer + const uint32 _bufSize; + + /** + * Write out the data in the buffer. + * + * @note This method is identical to flush() (which actually is + * implemented by calling this method), except that it is not + * virtual, hence there is less overhead calling it. + */ + bool flushBuffer(); public: BufferedWriteStream(WriteStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO); virtual ~BufferedWriteStream(); virtual uint32 write(const void *dataPtr, uint32 dataSize); - virtual bool flush(); + virtual bool flush() { return flushBuffer(); } }; /** |