Avoid memcpy call for empty vectors (#6111)

Co-authored-by: kuddai <kuddai92@gmail.com>
This commit is contained in:
Ruslan Burakov 2020-09-10 23:03:15 +03:00 committed by GitHub
parent 92a8c1a0f2
commit f5ab24bc41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -1607,6 +1607,9 @@ class FlatBufferBuilder {
// causing the wrong overload to be selected, remove it.
AssertScalarT<T>();
StartVector(len, sizeof(T));
if (len == 0) {
return Offset<Vector<T>>(EndVector(len));
}
// clang-format off
#if FLATBUFFERS_LITTLEENDIAN
PushBytes(reinterpret_cast<const uint8_t *>(v), len * sizeof(T));