Przeglądaj źródła

Fix an oversight that dropped the buffer. (#3628)

This lost any seed or prior hashing done, which isn't good. I've added
some basic testing that would have caught this immediately.
Chandler Carruth 2 lat temu
rodzic
commit
5f62cf752d
2 zmienionych plików z 10 dodań i 1 usunięć
  1. 1 1
      common/hashing.h
  2. 9 0
      common/hashing_test.cpp

+ 1 - 1
common/hashing.h

@@ -691,7 +691,7 @@ inline auto Hasher::Hash(const T& value) -> void {
     // data to fully and densely populate all 8 bytes. For these cases we have a
     // `WeakMix` routine that is lower latency but lower quality.
     CARBON_MCA_BEGIN("fixed-8b");
-    buffer = WeakMix(ReadSmall(value));
+    buffer = WeakMix(buffer ^ ReadSmall(value));
     CARBON_MCA_END("fixed-8b");
     return;
   }

+ 9 - 0
common/hashing_test.cpp

@@ -86,6 +86,15 @@ TEST(HashingTest, Integers) {
   }
 }
 
+TEST(HashingTest, BasicSeeding) {
+  auto unseeded_hash = HashValue(42);
+  EXPECT_THAT(unseeded_hash, Ne(HashValue(42, 1)));
+  EXPECT_THAT(unseeded_hash, Ne(HashValue(42, 2)));
+  EXPECT_THAT(unseeded_hash, Ne(HashValue(42, 3)));
+  EXPECT_THAT(unseeded_hash,
+              Ne(HashValue(42, static_cast<uint64_t>(unseeded_hash))));
+}
+
 TEST(HashingTest, Pointers) {
   int object1 = 42;
   std::string object2 =