mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 13:37:25 +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:
@@ -3320,6 +3320,31 @@ void EqualOperatorTest() {
|
||||
TEST_EQ(b == a, true);
|
||||
TEST_EQ(b != a, false);
|
||||
|
||||
a.enemy.reset(new MonsterT());
|
||||
TEST_EQ(b != a, true);
|
||||
a.enemy->mana = 33;
|
||||
TEST_EQ(b == a, false);
|
||||
TEST_EQ(b != a, true);
|
||||
|
||||
b.enemy.reset(new MonsterT());
|
||||
TEST_EQ(b == a, false);
|
||||
TEST_EQ(b != a, true);
|
||||
b.enemy->mana = 33;
|
||||
TEST_EQ(b == a, true);
|
||||
TEST_EQ(b != a, false);
|
||||
|
||||
a.enemy.reset(nullptr);
|
||||
TEST_EQ(b == a, false);
|
||||
TEST_EQ(b != a, true);
|
||||
b.enemy->mana = 150;
|
||||
TEST_EQ(b == a, false);
|
||||
TEST_EQ(b != a, true);
|
||||
a.enemy.reset(new MonsterT());
|
||||
TEST_EQ(b == a, true);
|
||||
TEST_EQ(b != a, false);
|
||||
|
||||
b.enemy.reset(nullptr);
|
||||
|
||||
b.test.type = Any_Monster;
|
||||
TEST_EQ(b == a, false);
|
||||
TEST_EQ(b != a, true);
|
||||
|
||||
Reference in New Issue
Block a user