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

Side by Side Diff: Source/platform/heap/Heap.h

Issue 526023003: Oilpan: use template aliases for heap version of collections. Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Speculative windows compiler crash fix. Created 6 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/heap/Handle.h ('k') | Source/wtf/Deque.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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1742 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 COMPILE_ASSERT(!WTF::IsWeak<ValueArg>::value, WeakPointersInAListHashSet WillJustResultInNullEntriesInTheSetThatsNotWhatYouWantConsiderUsingLinkedHashSet Instead); 1753 COMPILE_ASSERT(!WTF::IsWeak<ValueArg>::value, WeakPointersInAListHashSet WillJustResultInNullEntriesInTheSetThatsNotWhatYouWantConsiderUsingLinkedHashSet Instead);
1754 return malloc<void*, Node>(sizeof(Node)); 1754 return malloc<void*, Node>(sizeof(Node));
1755 } 1755 }
1756 1756
1757 static void traceValue(Visitor* visitor, Node* node) 1757 static void traceValue(Visitor* visitor, Node* node)
1758 { 1758 {
1759 traceListHashSetValue(visitor, node->m_value); 1759 traceListHashSetValue(visitor, node->m_value);
1760 } 1760 }
1761 }; 1761 };
1762 1762
1763 // FIXME: These should just be template aliases:
1764 //
1765 // template<typename T, size_t inlineCapacity = 0>
1766 // using HeapVector = Vector<T, inlineCapacity, HeapAllocator>;
1767 //
1768 // as soon as all the compilers we care about support that.
1769 // MSVC supports it only in MSVC 2013.
1770 template< 1763 template<
1771 typename KeyArg, 1764 typename KeyArg,
1772 typename MappedArg, 1765 typename MappedArg,
1773 typename HashArg = typename DefaultHash<KeyArg>::Hash, 1766 typename HashArg = typename DefaultHash<KeyArg>::Hash,
1774 typename KeyTraitsArg = HashTraits<KeyArg>, 1767 typename KeyTraitsArg = HashTraits<KeyArg>,
1775 typename MappedTraitsArg = HashTraits<MappedArg> > 1768 typename MappedTraitsArg = HashTraits<MappedArg> >
1776 class HeapHashMap : public HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, Map pedTraitsArg, HeapAllocator> { }; 1769 using HeapHashMap = HashMap<KeyArg, MappedArg, HashArg, KeyTraitsArg, MappedTrai tsArg, HeapAllocator>;
1777 1770
1778 template< 1771 template<
1779 typename ValueArg, 1772 typename ValueArg,
1780 typename HashArg = typename DefaultHash<ValueArg>::Hash, 1773 typename HashArg = typename DefaultHash<ValueArg>::Hash,
1781 typename TraitsArg = HashTraits<ValueArg> > 1774 typename TraitsArg = HashTraits<ValueArg> >
1782 class HeapHashSet : public HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator> { }; 1775 using HeapHashSet = HashSet<ValueArg, HashArg, TraitsArg, HeapAllocator>;
1783 1776
1784 template< 1777 template<
1785 typename ValueArg, 1778 typename ValueArg,
1786 typename HashArg = typename DefaultHash<ValueArg>::Hash, 1779 typename HashArg = typename DefaultHash<ValueArg>::Hash,
1787 typename TraitsArg = HashTraits<ValueArg> > 1780 typename TraitsArg = HashTraits<ValueArg> >
1788 class HeapLinkedHashSet : public LinkedHashSet<ValueArg, HashArg, TraitsArg, Hea pAllocator> { }; 1781 using HeapLinkedHashSet = LinkedHashSet<ValueArg, HashArg, TraitsArg, HeapAlloca tor>;
1789 1782
1790 template< 1783 template<
1791 typename ValueArg, 1784 typename ValueArg,
1792 size_t inlineCapacity = 0, // The inlineCapacity is just a dummy to match Li stHashSet (off-heap). 1785 size_t inlineCapacity = 0, // The inlineCapacity is just a dummy to match Li stHashSet (off-heap).
1793 typename HashArg = typename DefaultHash<ValueArg>::Hash> 1786 typename HashArg = typename DefaultHash<ValueArg>::Hash>
1794 class HeapListHashSet : public ListHashSet<ValueArg, inlineCapacity, HashArg, He apListHashSetAllocator<ValueArg, inlineCapacity> > { }; 1787 using HeapListHashSet = ListHashSet<ValueArg, inlineCapacity, HashArg, HeapListH ashSetAllocator<ValueArg, inlineCapacity> >;
1795 1788
1796 template< 1789 template<
1797 typename Value, 1790 typename Value,
1798 typename HashFunctions = typename DefaultHash<Value>::Hash, 1791 typename HashFunctions = typename DefaultHash<Value>::Hash,
1799 typename Traits = HashTraits<Value> > 1792 typename Traits = HashTraits<Value> >
1800 class HeapHashCountedSet : public HashCountedSet<Value, HashFunctions, Traits, H eapAllocator> { }; 1793 using HeapHashCountedSet = HashCountedSet<Value, HashFunctions, Traits, HeapAllo cator>;
1801 1794
1802 template<typename T, size_t inlineCapacity = 0> 1795 template<typename T, size_t inlineCapacity = 0>
1803 class HeapVector : public Vector<T, inlineCapacity, HeapAllocator> { 1796 using HeapVector = Vector<T, inlineCapacity, HeapAllocator>;
1804 public:
1805 HeapVector() { }
1806
1807 explicit HeapVector(size_t size) : Vector<T, inlineCapacity, HeapAllocator>( size)
1808 {
1809 }
1810
1811 HeapVector(size_t size, const T& val) : Vector<T, inlineCapacity, HeapAlloca tor>(size, val)
1812 {
1813 }
1814
1815 template<size_t otherCapacity>
1816 HeapVector(const HeapVector<T, otherCapacity>& other)
1817 : Vector<T, inlineCapacity, HeapAllocator>(other)
1818 {
1819 }
1820
1821 template<typename U>
1822 void append(const U& other)
1823 {
1824 Vector<T, inlineCapacity, HeapAllocator>::append(other);
1825 }
1826
1827 template<typename U, size_t otherCapacity>
1828 void appendVector(const HeapVector<U, otherCapacity>& other)
1829 {
1830 const Vector<U, otherCapacity, HeapAllocator>& otherVector = other;
1831 Vector<T, inlineCapacity, HeapAllocator>::appendVector(otherVector);
1832 }
1833 };
1834 1797
1835 template<typename T, size_t inlineCapacity = 0> 1798 template<typename T, size_t inlineCapacity = 0>
1836 class HeapDeque : public Deque<T, inlineCapacity, HeapAllocator> { 1799 using HeapDeque = Deque<T, inlineCapacity, HeapAllocator>;
1837 public:
1838 HeapDeque() { }
1839
1840 explicit HeapDeque(size_t size) : Deque<T, inlineCapacity, HeapAllocator>(si ze)
1841 {
1842 }
1843
1844 HeapDeque(size_t size, const T& val) : Deque<T, inlineCapacity, HeapAllocato r>(size, val)
1845 {
1846 }
1847
1848 // FIXME: Doesn't work if there is an inline buffer, due to crbug.com/360572
1849 HeapDeque<T, 0>& operator=(const HeapDeque& other)
1850 {
1851 HeapDeque<T> copy(other);
1852 swap(copy);
1853 return *this;
1854 }
1855
1856 // FIXME: Doesn't work if there is an inline buffer, due to crbug.com/360572
1857 inline void swap(HeapDeque& other)
1858 {
1859 Deque<T, inlineCapacity, HeapAllocator>::swap(other);
1860 }
1861
1862 template<size_t otherCapacity>
1863 HeapDeque(const HeapDeque<T, otherCapacity>& other)
1864 : Deque<T, inlineCapacity, HeapAllocator>(other)
1865 {
1866 }
1867
1868 template<typename U>
1869 void append(const U& other)
1870 {
1871 Deque<T, inlineCapacity, HeapAllocator>::append(other);
1872 }
1873 };
1874 1800
1875 template<typename T, size_t i> 1801 template<typename T, size_t i>
1876 inline void swap(HeapVector<T, i>& a, HeapVector<T, i>& b) { a.swap(b); } 1802 inline void swap(HeapVector<T, i>& a, HeapVector<T, i>& b) { a.swap(b); }
1877 template<typename T, size_t i> 1803 template<typename T, size_t i>
1878 inline void swap(HeapDeque<T, i>& a, HeapDeque<T, i>& b) { a.swap(b); } 1804 inline void swap(HeapDeque<T, i>& a, HeapDeque<T, i>& b) { a.swap(b); }
1879 template<typename T, typename U, typename V> 1805 template<typename T, typename U, typename V>
1880 inline void swap(HeapHashSet<T, U, V>& a, HeapHashSet<T, U, V>& b) { a.swap(b); } 1806 inline void swap(HeapHashSet<T, U, V>& a, HeapHashSet<T, U, V>& b) { a.swap(b); }
1881 template<typename T, typename U, typename V, typename W, typename X> 1807 template<typename T, typename U, typename V, typename W, typename X>
1882 inline void swap(HeapHashMap<T, U, V, W, X>& a, HeapHashMap<T, U, V, W, X>& b) { a.swap(b); } 1808 inline void swap(HeapHashMap<T, U, V, W, X>& a, HeapHashMap<T, U, V, W, X>& b) { a.swap(b); }
1883 template<typename T, size_t i, typename U> 1809 template<typename T, size_t i, typename U>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 1865
1940 template<typename Table> 1866 template<typename Table>
1941 struct ThreadingTrait<HeapHashTableBacking<Table> > { 1867 struct ThreadingTrait<HeapHashTableBacking<Table> > {
1942 typedef typename Table::KeyType Key; 1868 typedef typename Table::KeyType Key;
1943 typedef typename Table::ValueType Value; 1869 typedef typename Table::ValueType Value;
1944 static const ThreadAffinity Affinity = 1870 static const ThreadAffinity Affinity =
1945 (ThreadingTrait<Key>::Affinity == MainThreadOnly) 1871 (ThreadingTrait<Key>::Affinity == MainThreadOnly)
1946 && (ThreadingTrait<Value>::Affinity == MainThreadOnly) ? MainThreadOnly : AnyThread; 1872 && (ThreadingTrait<Value>::Affinity == MainThreadOnly) ? MainThreadOnly : AnyThread;
1947 }; 1873 };
1948 1874
1949 template<typename T, typename U, typename V, typename W, typename X>
1950 struct ThreadingTrait<HeapHashMap<T, U, V, W, X> > : public ThreadingTrait<HashM ap<T, U, V, W, X, HeapAllocator> > { };
1951
1952 template<typename T, typename U, typename V>
1953 struct ThreadingTrait<HeapHashSet<T, U, V> > : public ThreadingTrait<HashSet<T, U, V, HeapAllocator> > { };
1954
1955 template<typename T, size_t inlineCapacity>
1956 struct ThreadingTrait<HeapVector<T, inlineCapacity> > : public ThreadingTrait<Ve ctor<T, inlineCapacity, HeapAllocator> > { };
1957
1958 template<typename T, size_t inlineCapacity>
1959 struct ThreadingTrait<HeapDeque<T, inlineCapacity> > : public ThreadingTrait<Deq ue<T, inlineCapacity, HeapAllocator> > { };
1960
1961 template<typename T, typename U, typename V>
1962 struct ThreadingTrait<HeapHashCountedSet<T, U, V> > : public ThreadingTrait<Hash CountedSet<T, U, V, HeapAllocator> > { };
1963
1964 // The standard implementation of GCInfoTrait<T>::get() just returns a static 1875 // The standard implementation of GCInfoTrait<T>::get() just returns a static
1965 // from the class T, but we can't do that for HashMap, HashSet, Vector, etc. 1876 // from the class T, but we can't do that for HashMap, HashSet, Vector, etc.
1966 // because they are in WTF and know nothing of GCInfos. Instead we have a 1877 // because they are in WTF and know nothing of GCInfos. Instead we have a
1967 // specialization of GCInfoTrait for these four classes here. 1878 // specialization of GCInfoTrait for these four classes here.
1968 1879
1969 template<typename Key, typename Value, typename T, typename U, typename V> 1880 template<typename Key, typename Value, typename T, typename U, typename V>
1970 struct GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> > { 1881 struct GCInfoTrait<HashMap<Key, Value, T, U, V, HeapAllocator> > {
1971 static const GCInfo* get() 1882 static const GCInfo* get()
1972 { 1883 {
1973 typedef HashMap<Key, Value, T, U, V, HeapAllocator> TargetType; 1884 typedef HashMap<Key, Value, T, U, V, HeapAllocator> TargetType;
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 // Use the payload size as recorded by the heap to determine how many 2403 // Use the payload size as recorded by the heap to determine how many
2493 // elements to finalize. 2404 // elements to finalize.
2494 size_t length = header->payloadSize() / sizeof(Value); 2405 size_t length = header->payloadSize() / sizeof(Value);
2495 Value* table = reinterpret_cast<Value*>(pointer); 2406 Value* table = reinterpret_cast<Value*>(pointer);
2496 for (unsigned i = 0; i < length; i++) { 2407 for (unsigned i = 0; i < length; i++) {
2497 if (!Table::isEmptyOrDeletedBucket(table[i])) 2408 if (!Table::isEmptyOrDeletedBucket(table[i]))
2498 table[i].~Value(); 2409 table[i].~Value();
2499 } 2410 }
2500 } 2411 }
2501 2412
2502 template<typename T, typename U, typename V, typename W, typename X>
2503 struct GCInfoTrait<HeapHashMap<T, U, V, W, X> > : public GCInfoTrait<HashMap<T, U, V, W, X, HeapAllocator> > { };
2504 template<typename T, typename U, typename V>
2505 struct GCInfoTrait<HeapHashSet<T, U, V> > : public GCInfoTrait<HashSet<T, U, V, HeapAllocator> > { };
2506 template<typename T, typename U, typename V>
2507 struct GCInfoTrait<HeapLinkedHashSet<T, U, V> > : public GCInfoTrait<LinkedHashS et<T, U, V, HeapAllocator> > { };
2508 template<typename T, size_t inlineCapacity, typename U>
2509 struct GCInfoTrait<HeapListHashSet<T, inlineCapacity, U> > : public GCInfoTrait< ListHashSet<T, inlineCapacity, U, HeapListHashSetAllocator<T, inlineCapacity> > > { };
2510 template<typename T, size_t inlineCapacity>
2511 struct GCInfoTrait<HeapVector<T, inlineCapacity> > : public GCInfoTrait<Vector<T , inlineCapacity, HeapAllocator> > { };
2512 template<typename T, size_t inlineCapacity>
2513 struct GCInfoTrait<HeapDeque<T, inlineCapacity> > : public GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator> > { };
2514 template<typename T, typename U, typename V>
2515 struct GCInfoTrait<HeapHashCountedSet<T, U, V> > : public GCInfoTrait<HashCounte dSet<T, U, V, HeapAllocator> > { };
2516
2517 template<typename T> 2413 template<typename T>
2518 struct IfWeakMember; 2414 struct IfWeakMember;
2519 2415
2520 template<typename T> 2416 template<typename T>
2521 struct IfWeakMember { 2417 struct IfWeakMember {
2522 template<typename U> 2418 template<typename U>
2523 static bool isDead(Visitor*, const U&) { return false; } 2419 static bool isDead(Visitor*, const U&) { return false; }
2524 }; 2420 };
2525 2421
2526 template<typename T> 2422 template<typename T>
2527 struct IfWeakMember<WeakMember<T> > { 2423 struct IfWeakMember<WeakMember<T> > {
2528 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); } 2424 static bool isDead(Visitor* visitor, const WeakMember<T>& t) { return !visit or->isAlive(t.get()); }
2529 }; 2425 };
2530 2426
2531 } 2427 }
2532 2428
2533 #endif // Heap_h 2429 #endif // Heap_h
OLDNEW
« no previous file with comments | « Source/platform/heap/Handle.h ('k') | Source/wtf/Deque.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698