From 04a28fce81c737b6505e6c542a14d8529c9f891d Mon Sep 17 00:00:00 2001 From: Gil Date: Sun, 6 May 2018 14:12:20 -0700 Subject: Make BasePath hash directly as a range (#1232) Remove BasePath.Hash() Objective-C compatibility method Make DocumentKey's hasher use BasePath's segment-based hash code. --- Firestore/core/src/firebase/firestore/model/base_path.h | 8 -------- Firestore/core/src/firebase/firestore/model/document_key.h | 2 +- Firestore/core/src/firebase/firestore/model/field_mask.h | 7 ++----- Firestore/core/src/firebase/firestore/model/field_transform.h | 5 ++--- 4 files changed, 5 insertions(+), 17 deletions(-) (limited to 'Firestore/core/src') diff --git a/Firestore/core/src/firebase/firestore/model/base_path.h b/Firestore/core/src/firebase/firestore/model/base_path.h index 59a9b5a..58df6f0 100644 --- a/Firestore/core/src/firebase/firestore/model/base_path.h +++ b/Firestore/core/src/firebase/firestore/model/base_path.h @@ -160,14 +160,6 @@ class BasePath { return segments_ >= rhs.segments_; } -#if defined(__OBJC__) - // For Objective-C++ hash; to be removed after migration. - // Do NOT use in C++ code. - size_t Hash() const { - return util::Hash(segments_); - } -#endif // defined(__OBJC__) - protected: BasePath() = default; template diff --git a/Firestore/core/src/firebase/firestore/model/document_key.h b/Firestore/core/src/firebase/firestore/model/document_key.h index f6f4bf1..3f5f342 100644 --- a/Firestore/core/src/firebase/firestore/model/document_key.h +++ b/Firestore/core/src/firebase/firestore/model/document_key.h @@ -121,7 +121,7 @@ inline bool operator>=(const DocumentKey& lhs, const DocumentKey& rhs) { struct DocumentKeyHash { size_t operator()(const DocumentKey& key) const { - return util::Hash(key.ToString()); + return util::Hash(key.path()); } }; diff --git a/Firestore/core/src/firebase/firestore/model/field_mask.h b/Firestore/core/src/firebase/firestore/model/field_mask.h index 6075519..431e05a 100644 --- a/Firestore/core/src/firebase/firestore/model/field_mask.h +++ b/Firestore/core/src/firebase/firestore/model/field_mask.h @@ -23,6 +23,7 @@ #include #include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/util/hashing.h" namespace firebase { namespace firestore { @@ -86,11 +87,7 @@ class FieldMask { } NSUInteger Hash() const { - NSUInteger hashResult = 0; - for (const FieldPath& field : fields_) { - hashResult = hashResult * 31u + field.Hash(); - } - return hashResult; + return util::Hash(fields_); } #endif diff --git a/Firestore/core/src/firebase/firestore/model/field_transform.h b/Firestore/core/src/firebase/firestore/model/field_transform.h index a1dd96c..1a7127a 100644 --- a/Firestore/core/src/firebase/firestore/model/field_transform.h +++ b/Firestore/core/src/firebase/firestore/model/field_transform.h @@ -22,6 +22,7 @@ #include "Firestore/core/src/firebase/firestore/model/field_path.h" #include "Firestore/core/src/firebase/firestore/model/transform_operations.h" +#include "Firestore/core/src/firebase/firestore/util/hashing.h" namespace firebase { namespace firestore { @@ -51,9 +52,7 @@ class FieldTransform { // For Objective-C++ hash; to be removed after migration. // Do NOT use in C++ code. NSUInteger Hash() const { - NSUInteger hash = path_.Hash(); - hash = hash * 31 + transformation_->Hash(); - return hash; + return util::Hash(path_, transformation_->Hash()); } #endif // defined(__OBJC__) -- cgit v1.2.3