| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #include "heap/Heap.h" | 34 #include "heap/Heap.h" |
| 35 #include "heap/Visitor.h" | 35 #include "heap/Visitor.h" |
| 36 #include <wtf/HashFunctions.h> | 36 #include <wtf/HashFunctions.h> |
| 37 #include <wtf/HashMap.h> | 37 #include <wtf/HashMap.h> |
| 38 #include <wtf/HashTraits.h> | 38 #include <wtf/HashTraits.h> |
| 39 #include <wtf/Noncopyable.h> | 39 #include <wtf/Noncopyable.h> |
| 40 #include <wtf/TypeTraits.h> | 40 #include <wtf/TypeTraits.h> |
| 41 #include <wtf/Vector.h> | 41 #include <wtf/Vector.h> |
| 42 | 42 |
| 43 namespace WTF { |
| 44 |
| 45 template<typename A, typename B, typename C, typename D, typename E, typename F,
typename G> class HashTableConstIterator; |
| 46 |
| 47 } |
| 48 |
| 43 namespace WebCore { | 49 namespace WebCore { |
| 44 | 50 |
| 45 // Forward declarations. | 51 // Forward declarations. |
| 46 template<typename T> class Result; | 52 template<typename T> class Result; |
| 47 template<typename T> class Handle; | 53 template<typename T> class Handle; |
| 48 template<typename T> class Member; | 54 template<typename T> class Member; |
| 49 template<typename T> struct HeapObjectHash; | 55 template<typename T> struct HeapObjectHash; |
| 50 | 56 |
| 51 /* | 57 /* |
| 52 * Handles are used to store pointers into the managed heap. | 58 * Handles are used to store pointers into the managed heap. |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 758 |
| 753 // FIXME(oilpan): Remove once TreeShared no longer requires reference counti
ng. | 759 // FIXME(oilpan): Remove once TreeShared no longer requires reference counti
ng. |
| 754 PassRefPtr<T> passRefPtr() const | 760 PassRefPtr<T> passRefPtr() const |
| 755 { | 761 { |
| 756 return PassRefPtr<T>(releaseRaw()); | 762 return PassRefPtr<T>(releaseRaw()); |
| 757 } | 763 } |
| 758 | 764 |
| 759 Handle<T> handle() const { return Handle<T>(releaseRaw()); } | 765 Handle<T> handle() const { return Handle<T>(releaseRaw()); } |
| 760 | 766 |
| 761 private: | 767 private: |
| 768 template<typename U> |
| 769 Result(const Member<U>* other) |
| 770 : m_raw(other->raw()) |
| 771 #ifndef NDEBUG |
| 772 , m_doNotAllocate() |
| 773 #endif |
| 774 { |
| 775 } |
| 776 |
| 777 template<typename U> |
| 778 Result& operator=(const Member<U>* other) |
| 779 { |
| 780 COMPILE_ASSERT(!sizeof(T*), Result_should_never_be_assigned_to); |
| 781 return *this; |
| 782 } |
| 783 |
| 762 explicit Result(T* raw) | 784 explicit Result(T* raw) |
| 763 : m_raw(raw) | 785 : m_raw(raw) |
| 764 #ifndef NDEBUG | 786 #ifndef NDEBUG |
| 765 , m_doNotAllocate() | 787 , m_doNotAllocate() |
| 766 #endif | 788 #endif |
| 767 { | 789 { |
| 768 } | 790 } |
| 769 | 791 |
| 770 T* releaseRaw() const | 792 T* releaseRaw() const |
| 771 { | 793 { |
| 772 T* raw = m_raw; | 794 T* raw = m_raw; |
| 773 m_raw = 0; | 795 m_raw = 0; |
| 774 #ifndef NDEBUG | 796 #ifndef NDEBUG |
| 775 m_doNotAllocate.release(); | 797 m_doNotAllocate.release(); |
| 776 #endif | 798 #endif |
| 777 return raw; | 799 return raw; |
| 778 } | 800 } |
| 779 | 801 |
| 780 // Mutable to allow raw() to steal the pointer when creating a | 802 // Mutable to allow raw() to steal the pointer when creating a |
| 781 // Handle from the Result. | 803 // Handle from the Result. |
| 782 mutable T* m_raw; | 804 mutable T* m_raw; |
| 783 | 805 |
| 784 #ifndef NDEBUG | 806 #ifndef NDEBUG |
| 785 mutable NoAllocation m_doNotAllocate; | 807 mutable NoAllocation m_doNotAllocate; |
| 786 #endif | 808 #endif |
| 787 | 809 |
| 810 template<typename U> friend void Visitor::visit(const class Result<U>&); |
| 788 template<typename U> friend class Persistent; | 811 template<typename U> friend class Persistent; |
| 789 template<typename U> friend class Handle; | 812 template<typename U> friend class Handle; |
| 790 template<typename U> friend class Member; | 813 template<typename U> friend class Member; |
| 791 template<typename U> friend class Result; | 814 template<typename U> friend class Result; |
| 792 template<typename U> friend Result<U> adopt(U*); | 815 template<typename U> friend Result<U> adopt(U*); |
| 793 template<typename U> friend Result<U> adoptRawResult(U*); | 816 template<typename U> friend Result<U> adoptRawResult(U*); |
| 794 template<typename U> friend Result<U> adoptTreeShared(U*); | 817 template<typename U> friend Result<U> adoptTreeShared(U*); |
| 795 template<typename U, typename V> friend bool operator==(const Result<U>&, co
nst Handle<V>&); | 818 template<typename U, typename V> friend bool operator==(const Result<U>&, co
nst Handle<V>&); |
| 796 template<typename U, typename V> friend bool operator!=(const Result<U>&, co
nst Handle<V>&); | 819 template<typename U, typename V> friend bool operator!=(const Result<U>&, co
nst Handle<V>&); |
| 797 template<typename U, typename V> friend bool operator==(const Handle<U>&, co
nst Result<V>&); | 820 template<typename U, typename V> friend bool operator==(const Handle<U>&, co
nst Result<V>&); |
| 798 template<typename U, typename V> friend bool operator!=(const Handle<U>&, co
nst Result<V>&); | 821 template<typename U, typename V> friend bool operator!=(const Handle<U>&, co
nst Result<V>&); |
| 799 template<typename U, typename V> friend bool operator==(const Result<U>&, co
nst Persistent<V>&); | 822 template<typename U, typename V> friend bool operator==(const Result<U>&, co
nst Persistent<V>&); |
| 800 template<typename U, typename V> friend bool operator!=(const Result<U>&, co
nst Persistent<V>&); | 823 template<typename U, typename V> friend bool operator!=(const Result<U>&, co
nst Persistent<V>&); |
| 801 template<typename U, typename V> friend bool operator==(const Persistent<U>&
, const Result<V>&); | 824 template<typename U, typename V> friend bool operator==(const Persistent<U>&
, const Result<V>&); |
| 802 template<typename U, typename V> friend bool operator!=(const Persistent<U>&
, const Result<V>&); | 825 template<typename U, typename V> friend bool operator!=(const Persistent<U>&
, const Result<V>&); |
| 803 template<typename U, typename V> friend bool operator==(const Result<U>&, co
nst Member<V>&); | 826 template<typename U, typename V> friend bool operator==(const Result<U>&, co
nst Member<V>&); |
| 804 template<typename U, typename V> friend bool operator!=(const Result<U>&, co
nst Member<V>&); | 827 template<typename U, typename V> friend bool operator!=(const Result<U>&, co
nst Member<V>&); |
| 805 template<typename U, typename V> friend bool operator==(const Member<U>&, co
nst Result<V>&); | 828 template<typename U, typename V> friend bool operator==(const Member<U>&, co
nst Result<V>&); |
| 806 template<typename U, typename V> friend bool operator!=(const Member<U>&, co
nst Result<V>&); | 829 template<typename U, typename V> friend bool operator!=(const Member<U>&, co
nst Result<V>&); |
| 807 template<typename U, typename V> friend bool operator==(const Result<U>&, co
nst Result<V>&); | 830 template<typename U, typename V> friend bool operator==(const Result<U>&, co
nst Result<V>&); |
| 808 template<typename U, typename V> friend bool operator!=(const Result<U>&, co
nst Result<V>&); | 831 template<typename U, typename V> friend bool operator!=(const Result<U>&, co
nst Result<V>&); |
| 809 template<typename U, typename V> friend bool operator==(const Result<U>&, co
nst V*); | 832 template<typename U, typename V> friend bool operator==(const Result<U>&, co
nst V*); |
| 810 template<typename U, typename V> friend bool operator!=(const Result<U>&, co
nst V*); | 833 template<typename U, typename V> friend bool operator!=(const Result<U>&, co
nst V*); |
| 811 template<typename U, typename V> friend bool operator==(const U*, const Resu
lt<V>&); | 834 template<typename U, typename V> friend bool operator==(const U*, const Resu
lt<V>&); |
| 812 template<typename U, typename V> friend bool operator!=(const U*, const Resu
lt<V>&); | 835 template<typename U, typename V> friend bool operator!=(const U*, const Resu
lt<V>&); |
| 836 template<typename A, typename B, typename C, typename D, typename E, typenam
e F, typename G> friend class WTF::HashTableConstIterator; |
| 813 }; | 837 }; |
| 814 | 838 |
| 815 template<class T> | 839 template<class T> |
| 816 inline Result<T> adopt(T* raw) | 840 inline Result<T> adopt(T* raw) |
| 817 { | 841 { |
| 818 Shelter::adopt(raw); | 842 Shelter::adopt(raw); |
| 819 return Result<T>(raw); | 843 return Result<T>(raw); |
| 820 } | 844 } |
| 821 | 845 |
| 822 // Use of this function may indicate that you have a raw pointer | 846 // Use of this function may indicate that you have a raw pointer |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 // non-heap allocated hashes must arrange their own visiting. Eg. | 1370 // non-heap allocated hashes must arrange their own visiting. Eg. |
| 1347 // CollectionRoot visits the members in the collections it contains. | 1371 // CollectionRoot visits the members in the collections it contains. |
| 1348 static const bool needsVisiting = true; | 1372 static const bool needsVisiting = true; |
| 1349 | 1373 |
| 1350 static const bool needsDestruction = false; | 1374 static const bool needsDestruction = false; |
| 1351 // FIXME(oilpan): The distinction between PeekInType and PassInType is | 1375 // FIXME(oilpan): The distinction between PeekInType and PassInType is |
| 1352 // there for the sake of the reference counting handles. When they are gone | 1376 // there for the sake of the reference counting handles. When they are gone |
| 1353 // the two types can be merged into PassInType. | 1377 // the two types can be merged into PassInType. |
| 1354 typedef const typename WebCore::Handle<T>& PeekInType; | 1378 typedef const typename WebCore::Handle<T>& PeekInType; |
| 1355 typedef const typename WebCore::Handle<T>& PassInType; | 1379 typedef const typename WebCore::Handle<T>& PassInType; |
| 1380 typedef WebCore::Result<T> IteratorGetType; |
| 1381 typedef WebCore::Result<T> IteratorConstGetType; |
| 1382 typedef WebCore::Result<T> IteratorReferenceType; |
| 1383 typedef WebCore::Result<T> IteratorConstReferenceType; |
| 1384 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r
eturn x; } |
| 1385 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons
tGetType x) { return x; } |
| 1356 // FIXME(oilpan): Similarly, there is no need for a distinction between | 1386 // FIXME(oilpan): Similarly, there is no need for a distinction between |
| 1357 // PeekType and PassOutType without reference counting. | 1387 // PeekType and PassOutType without reference counting. |
| 1358 typedef typename WebCore::Result<T> PeekType; | 1388 typedef typename WebCore::Result<T> PeekType; |
| 1359 typedef typename WebCore::Result<T> PassOutType; | 1389 typedef typename WebCore::Result<T> PassOutType; |
| 1360 | 1390 |
| 1361 template<typename U> | 1391 template<typename U> |
| 1362 static void store(const U& value, WebCore::Member<T>& storage) { storage = v
alue; } | 1392 static void store(const U& value, WebCore::Member<T>& storage) { storage = v
alue; } |
| 1363 | 1393 |
| 1364 static PeekType peek(const WebCore::Member<T>& value) { return value; } | 1394 static PeekType peek(const WebCore::Member<T>& value) { return value; } |
| 1365 static PassOutType passOut(const WebCore::Member<T>& value) { return value;
} | 1395 static PassOutType passOut(const WebCore::Member<T>& value) { return value;
} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1380 typedef PtrHash<WebCore::Member<T> > Hash; | 1410 typedef PtrHash<WebCore::Member<T> > Hash; |
| 1381 }; | 1411 }; |
| 1382 | 1412 |
| 1383 #define DEFINE_SELF_HANDLE(Type) \ | 1413 #define DEFINE_SELF_HANDLE(Type) \ |
| 1384 Result<Type> selfHandle() { return adoptRawResult(this); } \ | 1414 Result<Type> selfHandle() { return adoptRawResult(this); } \ |
| 1385 Result<const Type> selfHandle() const { return adoptRawResult(this); } | 1415 Result<const Type> selfHandle() const { return adoptRawResult(this); } |
| 1386 | 1416 |
| 1387 } | 1417 } |
| 1388 | 1418 |
| 1389 #endif | 1419 #endif |
| OLD | NEW |