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

@@ -274,16 +274,6 @@ struct AttackerT : public flatbuffers::NativeTable {
int32_t sword_attack_damage = 0;
};
inline bool operator==(const AttackerT &lhs, const AttackerT &rhs) {
return
(lhs.sword_attack_damage == rhs.sword_attack_damage);
}
inline bool operator!=(const AttackerT &lhs, const AttackerT &rhs) {
return !(lhs == rhs);
}
struct Attacker FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef AttackerT NativeTableType;
typedef AttackerBuilder Builder;
@@ -349,17 +339,6 @@ struct MovieT : public flatbuffers::NativeTable {
std::vector<CharacterUnion> characters{};
};
inline bool operator==(const MovieT &lhs, const MovieT &rhs) {
return
(lhs.main_character == rhs.main_character) &&
(lhs.characters == rhs.characters);
}
inline bool operator!=(const MovieT &lhs, const MovieT &rhs) {
return !(lhs == rhs);
}
struct Movie FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef MovieT NativeTableType;
typedef MovieBuilder Builder;
@@ -490,6 +469,17 @@ inline flatbuffers::Offset<Movie> CreateMovieDirect(
flatbuffers::Offset<Movie> CreateMovie(flatbuffers::FlatBufferBuilder &_fbb, const MovieT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
inline bool operator==(const AttackerT &lhs, const AttackerT &rhs) {
return
(lhs.sword_attack_damage == rhs.sword_attack_damage);
}
inline bool operator!=(const AttackerT &lhs, const AttackerT &rhs) {
return !(lhs == rhs);
}
inline AttackerT *Attacker::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
auto _o = std::unique_ptr<AttackerT>(new AttackerT());
UnPackTo(_o.get(), _resolver);
@@ -516,6 +506,18 @@ inline flatbuffers::Offset<Attacker> CreateAttacker(flatbuffers::FlatBufferBuild
_sword_attack_damage);
}
inline bool operator==(const MovieT &lhs, const MovieT &rhs) {
return
(lhs.main_character == rhs.main_character) &&
(lhs.characters == rhs.characters);
}
inline bool operator!=(const MovieT &lhs, const MovieT &rhs) {
return !(lhs == rhs);
}
inline MovieT *Movie::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
auto _o = std::unique_ptr<MovieT>(new MovieT());
UnPackTo(_o.get(), _resolver);