Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1353)

Side by Side Diff: Source/wtf/HashTable.h

Issue 802203004: replace COMPILE_ASSERT with static assert in wtf/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: final fixups Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/wtf/BloomFilter.h ('k') | Source/wtf/ListHashSet.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2008 David Levin <levin@chromium.org> 3 * Copyright (C) 2008 David Levin <levin@chromium.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 template<unsigned size> 593 template<unsigned size>
594 struct HashTableCapacityForSizeSplitter<size, false> { 594 struct HashTableCapacityForSizeSplitter<size, false> {
595 static const unsigned value = UpperPowerOfTwoBound<size>::value; 595 static const unsigned value = UpperPowerOfTwoBound<size>::value;
596 }; 596 };
597 597
598 // HashTableCapacityForSize computes the upper power of two capacity to hold the size parameter. 598 // HashTableCapacityForSize computes the upper power of two capacity to hold the size parameter.
599 // This is done at compile time to initialize the HashTraits. 599 // This is done at compile time to initialize the HashTraits.
600 template<unsigned size> 600 template<unsigned size>
601 struct HashTableCapacityForSize { 601 struct HashTableCapacityForSize {
602 static const unsigned value = HashTableCapacityForSizeSplitter<size, !(s ize & (size - 1))>::value; 602 static const unsigned value = HashTableCapacityForSizeSplitter<size, !(s ize & (size - 1))>::value;
603 COMPILE_ASSERT(size > 0, HashTableNonZeroMinimumCapacity); 603 static_assert(size > 0, "HashTable minimum capacity should be > 0");
604 COMPILE_ASSERT(!static_cast<int>(value >> 31), HashTableNoCapacityOverfl ow); 604 static_assert(!static_cast<int>(value >> 31), "HashTable capacity should not overflow 32bit int");
605 COMPILE_ASSERT(value > (2 * size), HashTableCapacityHoldsContentSize); 605 static_assert(value > (2 * size), "HashTable capacity should be able to hold content size");
606 }; 606 };
607 607
608 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> 608 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
609 inline HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Al locator>::HashTable() 609 inline HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Al locator>::HashTable()
610 : m_table(0) 610 : m_table(0)
611 , m_tableSize(0) 611 , m_tableSize(0)
612 , m_keyCount(0) 612 , m_keyCount(0)
613 , m_deletedCount(0) 613 , m_deletedCount(0)
614 , m_queueFlag(false) 614 , m_queueFlag(false)
615 #if ENABLE(ASSERT) 615 #if ENABLE(ASSERT)
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> 986 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
987 Value* HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Al locator>::allocateTable(unsigned size) 987 Value* HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Al locator>::allocateTable(unsigned size)
988 { 988 {
989 size_t allocSize = size * sizeof(ValueType); 989 size_t allocSize = size * sizeof(ValueType);
990 ValueType* result; 990 ValueType* result;
991 // Assert that we will not use memset on things with a vtable entry. 991 // Assert that we will not use memset on things with a vtable entry.
992 // The compiler will also check this on some platforms. We would 992 // The compiler will also check this on some platforms. We would
993 // like to check this on the whole value (key-value pair), but 993 // like to check this on the whole value (key-value pair), but
994 // IsPolymorphic will return false for a pair of two types, even if 994 // IsPolymorphic will return false for a pair of two types, even if
995 // one of the components is polymorphic. 995 // one of the components is polymorphic.
996 COMPILE_ASSERT(!Traits::emptyValueIsZero || !IsPolymorphic<KeyType>::val ue, EmptyValueCannotBeZeroForThingsWithAVtable); 996 static_assert(!Traits::emptyValueIsZero || !IsPolymorphic<KeyType>::valu e, "empty value cannot be zero for things with a vtable");
997 if (Traits::emptyValueIsZero) { 997 if (Traits::emptyValueIsZero) {
998 result = Allocator::template allocateZeroedHashTableBacking<ValueTyp e, HashTable>(allocSize); 998 result = Allocator::template allocateZeroedHashTableBacking<ValueTyp e, HashTable>(allocSize);
999 } else { 999 } else {
1000 result = Allocator::template allocateHashTableBacking<ValueType, Has hTable>(allocSize); 1000 result = Allocator::template allocateHashTableBacking<ValueType, Has hTable>(allocSize);
1001 for (unsigned i = 0; i < size; i++) 1001 for (unsigned i = 0; i < size; i++)
1002 initializeBucket(result[i]); 1002 initializeBucket(result[i]);
1003 } 1003 }
1004 return result; 1004 return result;
1005 } 1005 }
1006 1006
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 CollectionIterator end(toBeRemoved.end()); 1378 CollectionIterator end(toBeRemoved.end());
1379 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) 1379 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it)
1380 collection.remove(*it); 1380 collection.remove(*it);
1381 } 1381 }
1382 1382
1383 } // namespace WTF 1383 } // namespace WTF
1384 1384
1385 #include "wtf/HashIterators.h" 1385 #include "wtf/HashIterators.h"
1386 1386
1387 #endif // WTF_HashTable_h 1387 #endif // WTF_HashTable_h
OLDNEW
« no previous file with comments | « Source/wtf/BloomFilter.h ('k') | Source/wtf/ListHashSet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698