mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-23 21:01:46 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user