OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 | 296 |
297 TEST(HashMapTest, ValueTypeDestructed) | 297 TEST(HashMapTest, ValueTypeDestructed) |
298 { | 298 { |
299 InstanceCounter::counter = 0; | 299 InstanceCounter::counter = 0; |
300 HashMap<int, InstanceCounter> map; | 300 HashMap<int, InstanceCounter> map; |
301 map.set(1, InstanceCounter()); | 301 map.set(1, InstanceCounter()); |
302 map.clear(); | 302 map.clear(); |
303 EXPECT_EQ(0, InstanceCounter::counter); | 303 EXPECT_EQ(0, InstanceCounter::counter); |
304 } | 304 } |
305 | 305 |
306 class CopyCounter { | |
307 public: | |
308 CopyCounter() = default; | |
309 explicit CopyCounter(int data) : m_data(data) { } | |
310 | |
311 CopyCounter(const CopyCounter& copy) : m_data(copy.m_data) { ++counter; } | |
312 | |
313 int data() const { return m_data; } | |
314 | |
315 bool isHashTableDeletedValue() const { return m_data == HashTableDeletedValu e; } | |
316 | |
317 static int counter; | |
tkent
2015/06/18 23:41:50
counter -> s_counter
| |
318 private: | |
319 int m_data; | |
320 }; | |
321 | |
322 int CopyCounter::counter = 0; | |
323 | |
324 struct CopyCounterHash { | |
325 static unsigned hash(const CopyCounter& key) | |
326 { | |
327 return IntHash<unsigned>::hash(key.data()); | |
328 } | |
329 | |
330 static bool equal(const CopyCounter& a, const CopyCounter& b) | |
331 { | |
332 return a.data() == b.data(); | |
333 } | |
334 | |
335 static const bool safeToCompareToEmptyOrDeleted = true; | |
336 }; | |
337 | |
338 | |
339 struct CopyCounterHashTraits: SimpleClassHashTraits<CopyCounter> { | |
340 static const bool hasIsEmptyValueFunction = true; | |
341 static bool isEmptyValue(const CopyCounter& counter) { return !counter.data( ); } | |
342 }; | |
343 | |
344 | |
345 TEST(HashMapTest, LookupNoKeyCopies) | |
346 { | |
347 HashMap<CopyCounter, int, CopyCounterHash, CopyCounterHashTraits> map; | |
348 | |
349 map.contains(CopyCounter(1)); | |
350 auto it = map.find(CopyCounter(1)); | |
351 ALLOW_UNUSED_LOCAL(it); | |
352 | |
353 EXPECT_EQ(0, CopyCounter::counter); | |
354 } | |
355 | |
306 } // anonymous namespace | 356 } // anonymous namespace |
307 | 357 |
308 } // namespace WTF | 358 } // namespace WTF |
OLD | NEW |