31
31
#include " absl/memory/memory.h"
32
32
#include " google/protobuf/message_lite.h"
33
33
34
- #if !defined(GOOGLE_PROTOBUF_NO_RDTSC) && defined(__APPLE__) && \
35
- (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
36
- #include < time.h>
37
- #endif
38
-
39
34
#include " absl/base/attributes.h"
40
35
#include " absl/container/btree_map.h"
41
36
#include " absl/hash/hash.h"
@@ -563,7 +558,6 @@ class PROTOBUF_EXPORT UntypedMapBase {
563
558
explicit constexpr UntypedMapBase (Arena* arena)
564
559
: num_elements_(0 ),
565
560
num_buckets_(internal::kGlobalEmptyTableSize ),
566
- seed_(0 ),
567
561
index_of_first_non_null_(internal::kGlobalEmptyTableSize ),
568
562
table_(const_cast <TableEntryPtr*>(internal::kGlobalEmptyTable )),
569
563
alloc_(arena) {}
@@ -581,7 +575,6 @@ class PROTOBUF_EXPORT UntypedMapBase {
581
575
void InternalSwap (UntypedMapBase* other) {
582
576
std::swap (num_elements_, other->num_elements_ );
583
577
std::swap (num_buckets_, other->num_buckets_ );
584
- std::swap (seed_, other->seed_ );
585
578
std::swap (index_of_first_non_null_, other->index_of_first_non_null_ );
586
579
std::swap (table_, other->table_ );
587
580
std::swap (alloc_, other->alloc_ );
@@ -621,7 +614,7 @@ class PROTOBUF_EXPORT UntypedMapBase {
621
614
return false ;
622
615
#else
623
616
// Doing modulo with a prime mixes the bits more.
624
- return ( reinterpret_cast < uintptr_t >( node) ^ seed_ ) % 13 > 6 ;
617
+ return absl::HashOf ( node, table_ ) % 13 > 6 ;
625
618
#endif
626
619
}
627
620
@@ -708,12 +701,12 @@ class PROTOBUF_EXPORT UntypedMapBase {
708
701
}
709
702
710
703
map_index_t VariantBucketNumber (absl::string_view key) const {
711
- return static_cast <map_index_t >(absl::HashOf (seed_, key ) &
704
+ return static_cast <map_index_t >(absl::HashOf (key, table_ ) &
712
705
(num_buckets_ - 1 ));
713
706
}
714
707
715
708
map_index_t VariantBucketNumber (uint64_t key) const {
716
- return static_cast <map_index_t >(absl::HashOf (key ^ seed_ ) &
709
+ return static_cast <map_index_t >(absl::HashOf (key, table_ ) &
717
710
(num_buckets_ - 1 ));
718
711
}
719
712
@@ -725,34 +718,6 @@ class PROTOBUF_EXPORT UntypedMapBase {
725
718
return result;
726
719
}
727
720
728
- // Return a randomish value.
729
- map_index_t Seed () const {
730
- uint64_t s = 0 ;
731
- #if !defined(GOOGLE_PROTOBUF_NO_RDTSC)
732
- #if defined(__APPLE__) && \
733
- (!defined (_POSIX_C_SOURCE) || defined (_DARWIN_C_SOURCE))
734
- // Use a commpage-based fast time function on Apple environments (MacOS,
735
- // iOS, tvOS, watchOS, etc), if we think the system headers expose it.
736
- s = clock_gettime_nsec_np (CLOCK_UPTIME_RAW);
737
- #elif defined(__x86_64__) && defined(__GNUC__)
738
- uint32_t hi, lo;
739
- asm volatile (" rdtsc" : " =a" (lo), " =d" (hi));
740
- s = ((static_cast <uint64_t >(hi) << 32 ) | lo);
741
- #elif defined(__aarch64__) && defined(__GNUC__)
742
- // There is no rdtsc on ARMv8. CNTVCT_EL0 is the virtual counter of the
743
- // system timer. It runs at a different frequency than the CPU's, but is
744
- // the best source of time-based entropy we get.
745
- uint64_t virtual_timer_value;
746
- asm volatile (" mrs %0, cntvct_el0" : " =r" (virtual_timer_value));
747
- s = virtual_timer_value;
748
- #endif
749
- #endif // !defined(GOOGLE_PROTOBUF_NO_RDTSC)
750
- // Add entropy from the address of the map and the address of the table
751
- // array.
752
- return static_cast <map_index_t >(
753
- absl::HashOf (s, table_, static_cast <const void *>(this )));
754
- }
755
-
756
721
enum {
757
722
kKeyIsString = 1 << 0 ,
758
723
kValueIsString = 1 << 1 ,
@@ -812,7 +777,6 @@ class PROTOBUF_EXPORT UntypedMapBase {
812
777
813
778
map_index_t num_elements_;
814
779
map_index_t num_buckets_;
815
- map_index_t seed_;
816
780
map_index_t index_of_first_non_null_;
817
781
TableEntryPtr* table_; // an array with num_buckets_ entries
818
782
Allocator alloc_;
@@ -1096,7 +1060,6 @@ class KeyMapBase : public UntypedMapBase {
1096
1060
// Just overwrite with a new one. No need to transfer or free anything.
1097
1061
num_buckets_ = index_of_first_non_null_ = kMinTableSize ;
1098
1062
table_ = CreateEmptyTable (num_buckets_);
1099
- seed_ = Seed ();
1100
1063
return ;
1101
1064
}
1102
1065
0 commit comments