Skip to content

Commit 3a0eb06

Browse files
Review
1 parent 62237e0 commit 3a0eb06

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

Firestore/core/src/model/object_value.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "Firestore/core/src/nanopb/fields_array.h"
2525
#include "Firestore/core/src/nanopb/message.h"
2626
#include "Firestore/core/src/nanopb/nanopb_util.h"
27+
#include "Firestore/core/src/util/hashing.h"
2728
#include "absl/types/span.h"
2829

2930
namespace firebase {
@@ -53,6 +54,7 @@ struct MapEntryKeyCompare {
5354
}
5455
};
5556

57+
/** Traverses a Value proto and sorts all MapValues by key. */
5658
void SortFields(google_firestore_v1_Value& value) {
5759
if (value.which_value_type == google_firestore_v1_Value_map_value_tag) {
5860
google_firestore_v1_MapValue& map_value = value.map_value;
@@ -355,7 +357,7 @@ std::string ObjectValue::ToString() const {
355357
}
356358

357359
size_t ObjectValue::Hash() const {
358-
return std::hash<std::string>()(CanonicalId(*value_));
360+
return util::Hash(CanonicalId(*value_));
359361
}
360362

361363
/**

Firestore/core/src/model/object_value.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,23 @@ class ObjectValue {
4545
explicit ObjectValue(const google_firestore_v1_Value& value);
4646

4747
ObjectValue(ObjectValue&& other) noexcept = default;
48-
ObjectValue& operator=(ObjectValue&& other) = default;
48+
ObjectValue& operator=(ObjectValue&& other) noexcept = default;
4949
ObjectValue(const ObjectValue& other);
5050

5151
ObjectValue& operator=(const ObjectValue&) = delete;
5252

53+
/**
54+
* Creates a new ObjectValue that is backed by the given `map_value`.
55+
* ObjectValue takes on ownership of the data.
56+
*/
5357
static ObjectValue FromMapValue(google_firestore_v1_MapValue map_value);
58+
59+
/**
60+
* Creates a new ObjectValue that is backed by the provided document fields.
61+
* ObjectValue takes on ownership of the data and zeroes out the pointers in
62+
* `fields_entry`. This allows the callsite to destruct the Document proto
63+
* without affecting the fields data.
64+
*/
5465
static ObjectValue FromFieldsEntry(
5566
google_firestore_v1_Document_FieldsEntry* fields_entry, pb_size_t count);
5667

Firestore/core/test/unit/model/object_value_test.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ TEST_F(ObjectValueTest, ExtractsFields) {
4848
ASSERT_EQ(google_firestore_v1_Value_map_value_tag,
4949
value.Get(Field("foo"))->which_value_type);
5050

51-
EXPECT_TRUE(Value(1) == *value.Get(Field("foo.a")));
52-
EXPECT_TRUE(Value(true) == *value.Get(Field("foo.b")));
53-
EXPECT_TRUE(Value("string") == *value.Get(Field("foo.c")));
51+
EXPECT_EQ(Value(1), *value.Get(Field("foo.a")));
52+
EXPECT_EQ(Value(true), *value.Get(Field("foo.b")));
53+
EXPECT_EQ(Value("string"), *value.Get(Field("foo.c")));
5454

55-
EXPECT_TRUE(nullopt == value.Get(Field("foo.a.b")));
56-
EXPECT_TRUE(nullopt == value.Get(Field("bar")));
57-
EXPECT_TRUE(nullopt == value.Get(Field("bar.a")));
55+
EXPECT_EQ(nullopt, value.Get(Field("foo.a.b")));
56+
EXPECT_EQ(nullopt, value.Get(Field("bar")));
57+
EXPECT_EQ(nullopt, value.Get(Field("bar.a")));
5858
}
5959

6060
TEST_F(ObjectValueTest, ExtractsFieldMask) {

0 commit comments

Comments
 (0)