Cleaned up FlatBufferBuilder clearing.

Change-Id: I81cf4d268670bdd11d1d56ca9f2de78c120df842
Tested: on Linux.
parent f0769b60
...@@ -538,23 +538,23 @@ class vector_downward { ...@@ -538,23 +538,23 @@ class vector_downward {
if (buf_) { if (buf_) {
assert(allocator_); assert(allocator_);
allocator_->deallocate(buf_, reserved_); allocator_->deallocate(buf_, reserved_);
}
reserved_ = 0;
buf_ = nullptr; buf_ = nullptr;
cur_ = nullptr; }
scratch_ = nullptr; clear();
} }
void clear() { void clear() {
if (buf_) { if (buf_) {
cur_ = buf_ + reserved_; cur_ = buf_ + reserved_;
scratch_ = buf_;
} else { } else {
reserved_ = 0; reserved_ = 0;
buf_ = nullptr;
cur_ = nullptr; cur_ = nullptr;
scratch_ = nullptr;
} }
clear_scratch();
}
void clear_scratch() {
scratch_ = buf_;
} }
// Relinquish the pointer to the caller. // Relinquish the pointer to the caller.
...@@ -563,10 +563,8 @@ class vector_downward { ...@@ -563,10 +563,8 @@ class vector_downward {
size()); size());
allocator_ = nullptr; allocator_ = nullptr;
own_allocator_ = false; own_allocator_ = false;
reserved_ = 0;
buf_ = nullptr; buf_ = nullptr;
cur_ = nullptr; clear();
scratch_ = nullptr;
return fb; return fb;
} }
...@@ -1534,6 +1532,7 @@ class FlatBufferBuilder { ...@@ -1534,6 +1532,7 @@ class FlatBufferBuilder {
void Finish(uoffset_t root, const char *file_identifier, bool size_prefix) { void Finish(uoffset_t root, const char *file_identifier, bool size_prefix) {
NotNested(); NotNested();
buf_.clear_scratch();
// This will cause the whole buffer to be aligned. // This will cause the whole buffer to be aligned.
PreAlign((size_prefix ? sizeof(uoffset_t) : 0) + sizeof(uoffset_t) + PreAlign((size_prefix ? sizeof(uoffset_t) : 0) + sizeof(uoffset_t) +
(file_identifier ? kFileIdentifierLength : 0), (file_identifier ? kFileIdentifierLength : 0),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment