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

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));