From cf14183bcd5485b4a71541599ddce0b35eb71352 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Thu, 28 Apr 2016 14:34:59 -0700 Subject: Down integrate from Google internal. --- src/google/protobuf/map_test.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/google/protobuf/map_test.cc') diff --git a/src/google/protobuf/map_test.cc b/src/google/protobuf/map_test.cc index e833699a..9d4d6c13 100644 --- a/src/google/protobuf/map_test.cc +++ b/src/google/protobuf/map_test.cc @@ -307,6 +307,11 @@ static int64 Now() { google::protobuf::util::TimeUtil::GetCurrentTime()); } +// Arbitrary odd integers for creating test data. +static int k0 = 812398771; +static int k1 = 1312938717; +static int k2 = 1321555333; + // A naive begin() implementation will cause begin() to get slower and slower // if one erases elements at the "front" of the hash map, and we'd like to // avoid that, as std::unordered_map does. @@ -315,8 +320,18 @@ TEST_P(MapImplTest, BeginIsFast) { if (/*GetParam()*/true) return; Map map(false); // This test uses new-style maps only. const int kTestSize = 250000; - for (int i = 0; i < kTestSize; i++) { - map[i] = i; + // Create a random-looking map of size n. Use non-negative integer keys. + uint32 frog = 123983; + int last_key = 0; + int counter = 0; + while (map.size() < kTestSize) { + frog *= static_cast(k0); + frog ^= frog >> 17; + frog += counter++; + last_key = + static_cast(frog) >= 0 ? static_cast(frog) : last_key ^ 1; + GOOGLE_DCHECK_GE(last_key, 0); + map[last_key] = last_key ^ 1; } vector times; // We're going to do map.erase(map.begin()) over and over again. But, @@ -384,11 +399,6 @@ TEST_P(MapImplTest, HashFlood) { EXPECT_LE(x1, x0 * 20); } -// Arbitrary odd integers for creating test data. -static int k0 = 812398771; -static int k1 = 1312938717; -static int k2 = 1321555333; - template static void TestValidityForAllKeysExcept(int key_to_avoid, const T& check_map, -- cgit v1.2.3