mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 16:20:01 +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:
@@ -267,16 +267,6 @@ struct ArrayTableT : public flatbuffers::NativeTable {
|
||||
flatbuffers::unique_ptr<MyGame::Example::ArrayStruct> a{};
|
||||
};
|
||||
|
||||
inline bool operator==(const ArrayTableT &lhs, const ArrayTableT &rhs) {
|
||||
return
|
||||
(lhs.a == rhs.a);
|
||||
}
|
||||
|
||||
inline bool operator!=(const ArrayTableT &lhs, const ArrayTableT &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
struct ArrayTable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
typedef ArrayTableT NativeTableType;
|
||||
typedef ArrayTableBuilder Builder;
|
||||
@@ -330,6 +320,17 @@ inline flatbuffers::Offset<ArrayTable> CreateArrayTable(
|
||||
|
||||
flatbuffers::Offset<ArrayTable> CreateArrayTable(flatbuffers::FlatBufferBuilder &_fbb, const ArrayTableT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
||||
|
||||
inline bool operator==(const ArrayTableT &lhs, const ArrayTableT &rhs) {
|
||||
return
|
||||
((lhs.a == rhs.a) || (lhs.a && rhs.a && *lhs.a == *rhs.a));
|
||||
}
|
||||
|
||||
inline bool operator!=(const ArrayTableT &lhs, const ArrayTableT &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
inline ArrayTableT *ArrayTable::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = std::unique_ptr<ArrayTableT>(new ArrayTableT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
|
||||
Reference in New Issue
Block a user