@@ -523,51 +523,48 @@ class _FieldSet {
523
523
/// The hash may change when any field changes (recursively).
524
524
/// Therefore, protobufs used as map keys shouldn't be changed.
525
525
int get _hashCode {
526
- int hash;
527
-
528
- void hashEnumList (PbListBase enums) {
529
- for (ProtobufEnum enm in enums) {
530
- hash = 0x1fffffff & ((31 * hash) + enm.value);
531
- }
532
- }
533
-
534
526
// Hashes the value of one field (recursively).
535
- void hashField (FieldInfo fi, value) {
527
+ int hashField (int hash, FieldInfo fi, value) {
536
528
if (value is List && value.isEmpty) {
537
- return ; // It's either repeated or an empty byte array.
529
+ return hash ; // It's either repeated or an empty byte array.
538
530
}
539
- hash = 0x1fffffff & ((37 * hash) + fi.tagNumber);
531
+
532
+ hash = _HashUtils ._combine (hash, fi.tagNumber);
540
533
if (! _isEnum (fi.type)) {
541
- hash = 0x1fffffff & (( 53 * hash) + value.hashCode);
534
+ hash = _HashUtils . _combine ( hash, value.hashCode);
542
535
} else if (fi.isRepeated) {
543
- hashEnumList (value);
536
+ hash = _HashUtils . _hashObjects (value. map ((enm) => enm.value) );
544
537
} else {
545
538
ProtobufEnum enm = value;
546
- hash = 0x1fffffff & (( 53 * hash) + enm.value);
539
+ hash = _HashUtils . _combine ( hash, enm.value);
547
540
}
541
+
542
+ return hash;
548
543
}
549
544
550
- void hashEachField () {
551
- for (var fi in _infosSortedByTag) {
552
- var v = _values[fi.index];
553
- if (v != null ) hashField (fi, v);
554
- }
555
- if (! _hasExtensions) return ;
556
- for (int tagNumber in sorted (_extensions._tagNumbers)) {
545
+ int hashEachField (int hash) {
546
+ //non-extension fields
547
+ hash = _infosSortedByTag.where ((fi) => _values[fi.index] != null ).fold (
548
+ hash, (int h, FieldInfo fi) => hashField (h, fi, _values[fi.index]));
549
+
550
+ if (! _hasExtensions) return hash;
551
+
552
+ hash =
553
+ _sorted (_extensions._tagNumbers).fold (hash, (int h, int tagNumber) {
557
554
var fi = _extensions._getInfoOrNull (tagNumber);
558
- hashField (fi, _extensions._getFieldOrNull (fi));
559
- }
555
+ return hashField (h, fi, _extensions._getFieldOrNull (fi));
556
+ });
557
+
558
+ return hash;
560
559
}
561
560
562
- // Generate hash.
563
- hash = 41 ;
564
561
// Hash with descriptor.
565
- hash = 0x1fffffff & (( 19 * hash) + _meta.hashCode);
562
+ int hash = _HashUtils . _combine ( 0 , _meta.hashCode);
566
563
// Hash with fields.
567
- hashEachField ();
564
+ hash = hashEachField (hash );
568
565
// Hash with unknown fields.
569
566
if (_hasUnknownFields) {
570
- hash = 0x1fffffff & (( 29 * hash) + _unknownFields.hashCode);
567
+ hash = _HashUtils . _combine ( hash, _unknownFields.hashCode);
571
568
}
572
569
return hash;
573
570
}
0 commit comments