Improve generated comparisons for tables (#6486)

* Improve generated comparisons for tables

Previously, the generated code called std::unique_ptr<>::operator== on
non-scalar members, which would be correct only if the member was null
on both sides. After this CL, comparison is done on the pointed-to
values (including using a default-constructed value if the pointer is
null).

* Don't equate null Tables with all defaults

Also removes the cost of default-constructing tables for comparisons.

* Regenerate code

* fix formatting
This commit is contained in:
Mika Raento
2021-06-21 21:37:56 +03:00
committed by GitHub
parent 06fd6d640c
commit 962751a6ec
10 changed files with 362 additions and 297 deletions

View File

@@ -31,25 +31,6 @@ struct MonsterExtraT : public flatbuffers::NativeTable {
std::vector<float> fvec{};
};
inline bool operator==(const MonsterExtraT &lhs, const MonsterExtraT &rhs) {
return
(lhs.d0 == rhs.d0) &&
(lhs.d1 == rhs.d1) &&
(lhs.d2 == rhs.d2) &&
(lhs.d3 == rhs.d3) &&
(lhs.f0 == rhs.f0) &&
(lhs.f1 == rhs.f1) &&
(lhs.f2 == rhs.f2) &&
(lhs.f3 == rhs.f3) &&
(lhs.dvec == rhs.dvec) &&
(lhs.fvec == rhs.fvec);
}
inline bool operator!=(const MonsterExtraT &lhs, const MonsterExtraT &rhs) {
return !(lhs == rhs);
}
struct MonsterExtra FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef MonsterExtraT NativeTableType;
typedef MonsterExtraBuilder Builder;
@@ -250,6 +231,26 @@ inline flatbuffers::Offset<MonsterExtra> CreateMonsterExtraDirect(
flatbuffers::Offset<MonsterExtra> CreateMonsterExtra(flatbuffers::FlatBufferBuilder &_fbb, const MonsterExtraT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
inline bool operator==(const MonsterExtraT &lhs, const MonsterExtraT &rhs) {
return
(lhs.d0 == rhs.d0) &&
(lhs.d1 == rhs.d1) &&
(lhs.d2 == rhs.d2) &&
(lhs.d3 == rhs.d3) &&
(lhs.f0 == rhs.f0) &&
(lhs.f1 == rhs.f1) &&
(lhs.f2 == rhs.f2) &&
(lhs.f3 == rhs.f3) &&
(lhs.dvec == rhs.dvec) &&
(lhs.fvec == rhs.fvec);
}
inline bool operator!=(const MonsterExtraT &lhs, const MonsterExtraT &rhs) {
return !(lhs == rhs);
}
inline MonsterExtraT *MonsterExtra::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
auto _o = std::unique_ptr<MonsterExtraT>(new MonsterExtraT());
UnPackTo(_o.get(), _resolver);