| Index: runtime/vm/datastream.h
|
| ===================================================================
|
| --- runtime/vm/datastream.h (revision 20419)
|
| +++ runtime/vm/datastream.h (working copy)
|
| @@ -136,22 +136,22 @@
|
| // Stream for writing various types into a buffer.
|
| class WriteStream : public ValueObject {
|
| public:
|
| - WriteStream(uint8_t** buffer, ReAlloc alloc, intptr_t increment_size) :
|
| + WriteStream(uint8_t** buffer, ReAlloc alloc, intptr_t initial_size) :
|
| buffer_(buffer),
|
| end_(NULL),
|
| current_(NULL),
|
| current_size_(0),
|
| alloc_(alloc),
|
| - increment_size_(increment_size) {
|
| + initial_size_(initial_size) {
|
| ASSERT(buffer != NULL);
|
| ASSERT(alloc != NULL);
|
| *buffer_ = reinterpret_cast<uint8_t*>(alloc_(NULL,
|
| 0,
|
| - increment_size_));
|
| + initial_size_));
|
| ASSERT(*buffer_ != NULL);
|
| current_ = *buffer_;
|
| - current_size_ = increment_size_;
|
| - end_ = *buffer_ + increment_size_;
|
| + current_size_ = initial_size_;
|
| + end_ = *buffer_ + initial_size_;
|
| }
|
|
|
| uint8_t* buffer() const { return *buffer_; }
|
| @@ -234,8 +234,12 @@
|
|
|
| void Resize(intptr_t size_needed) {
|
| intptr_t position = current_ - *buffer_;
|
| - intptr_t new_size = current_size_ +
|
| - Utils::RoundUp(size_needed, increment_size_);
|
| + intptr_t increment_size = current_size_;
|
| + if (size_needed > increment_size) {
|
| + increment_size = Utils::RoundUp(size_needed, initial_size_);
|
| + }
|
| + intptr_t new_size = current_size_ + increment_size;
|
| + ASSERT(new_size > current_size_);
|
| *buffer_ = reinterpret_cast<uint8_t*>(alloc_(*buffer_,
|
| current_size_,
|
| new_size));
|
| @@ -252,7 +256,7 @@
|
| uint8_t* current_;
|
| intptr_t current_size_;
|
| ReAlloc alloc_;
|
| - intptr_t increment_size_;
|
| + intptr_t initial_size_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(WriteStream);
|
| };
|
|
|