Skip to content

Commit

Permalink
COMMON: Remove MemoryWriteStreamDynamic::pos()
Browse files Browse the repository at this point in the history
It doesn't need to exist. The position and size are always the same;
they're the number of bytes written to. The capacity denotes the size
of the memory block.
  • Loading branch information
DrMcCoy committed Nov 28, 2016
1 parent 1e78997 commit c585942
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
20 changes: 5 additions & 15 deletions src/common/memwritestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ size_t MemoryWriteStream::size() const {


MemoryWriteStreamDynamic::MemoryWriteStreamDynamic(bool disposeMemory, size_t capacity) :
_data(0, disposeMemory), _ptr(0), _pos(0), _capacity(0), _size(0) {
_data(0, disposeMemory), _ptr(0), _capacity(0), _size(0) {

reserve(capacity);
}
Expand All @@ -107,30 +107,25 @@ void MemoryWriteStreamDynamic::reserve(size_t s) {

_data.dispose();
_data.reset(newData);
_ptr = _data.get() + _pos;
_ptr = _data.get() + _size;
}

void MemoryWriteStreamDynamic::ensureCapacity(size_t newLen) {
if (newLen <= _capacity)
return;

reserve(newLen);

_size = newLen;
}

size_t MemoryWriteStreamDynamic::write(const void *dataPtr, size_t dataSize) {
assert(dataPtr);

ensureCapacity(_pos + dataSize);
ensureCapacity(_size + dataSize);

std::memcpy(_ptr, dataPtr, dataSize);

_ptr += dataSize;
_pos += dataSize;

if ((size_t)_pos > _size)
_size = _pos;
_ptr += dataSize;
_size += dataSize;

return dataSize;
}
Expand All @@ -143,15 +138,10 @@ void MemoryWriteStreamDynamic::dispose() {
_data.dispose();

_ptr = 0;
_pos = 0;
_size = 0;
_capacity = 0;
}

size_t MemoryWriteStreamDynamic::pos() const {
return _pos;
}

size_t MemoryWriteStreamDynamic::size() const {
return _size;
}
Expand Down
2 changes: 0 additions & 2 deletions src/common/memwritestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class MemoryWriteStreamDynamic : boost::noncopyable, public WriteStream {
void setDisposable(bool disposeMemory);
void dispose();

size_t pos() const;
size_t size() const;

byte *getData();
Expand All @@ -102,7 +101,6 @@ class MemoryWriteStreamDynamic : boost::noncopyable, public WriteStream {
DisposableArray<byte> _data;

byte *_ptr;
size_t _pos;

size_t _capacity;
size_t _size;
Expand Down

0 comments on commit c585942

Please sign in to comment.