mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-30 00:12:01 +00:00
Cleaned up FlatBufferBuilder clearing.
Change-Id: I81cf4d268670bdd11d1d56ca9f2de78c120df842 Tested: on Linux.
This commit is contained in:
@@ -538,23 +538,23 @@ class vector_downward {
|
|||||||
if (buf_) {
|
if (buf_) {
|
||||||
assert(allocator_);
|
assert(allocator_);
|
||||||
allocator_->deallocate(buf_, reserved_);
|
allocator_->deallocate(buf_, reserved_);
|
||||||
|
buf_ = nullptr;
|
||||||
}
|
}
|
||||||
reserved_ = 0;
|
clear();
|
||||||
buf_ = nullptr;
|
|
||||||
cur_ = nullptr;
|
|
||||||
scratch_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|||||||
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 {
|
|||||||
|
|
||||||
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),
|
||||||
|
|||||||
Reference in New Issue
Block a user