Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / wtf / HashTraits.h
index eba0bd6..1c108df 100644 (file)
@@ -39,6 +39,11 @@ namespace WTF {
 
     template<bool isInteger, typename T> struct GenericHashTraitsBase;
 
+    enum ShouldWeakPointersBeMarkedStrongly {
+        WeakPointersActStrong,
+        WeakPointersActWeak
+    };
+
     template<typename T> struct GenericHashTraitsBase<false, T> {
         // The emptyValueIsZero flag is used to optimize allocation of empty hash tables with zeroed memory.
         static const bool emptyValueIsZero = false;
@@ -53,7 +58,7 @@ namespace WTF {
 
         // The starting table size. Can be overridden when we know beforehand that
         // a hash table will have at least N entries.
-#if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
+#if defined(MEMORY_SANITIZER_INITIAL_SIZE)
         static const unsigned minimumTableSize = 1;
 #else
         static const unsigned minimumTableSize = 8;
@@ -63,7 +68,7 @@ namespace WTF {
         struct NeedsTracingLazily {
             static const bool value = NeedsTracing<T>::value;
         };
-        static const bool isWeak = IsWeak<T>::value;
+        static const WeakHandlingFlag weakHandlingFlag = IsWeak<T>::value ? WeakHandlingInCollections : NoWeakHandlingInCollections;
     };
 
     // Default integer traits disallow both 0 and -1 as keys (max value instead of -1 for unsigned).
@@ -188,34 +193,7 @@ namespace WTF {
         static PeekOutType peek(std::nullptr_t) { return 0; }
     };
 
-    template<typename T> struct HashTraits<RawPtr<T> > : SimpleClassHashTraits<RawPtr<T> > {
-        typedef std::nullptr_t EmptyValueType;
-        static EmptyValueType emptyValue() { return nullptr; }
-
-        static const bool hasIsEmptyValueFunction = true;
-        static bool isEmptyValue(const RawPtr<T>& value) { return !value; }
-
-        static const bool needsDestruction = false;
-        typedef RawPtr<T> PeekInType;
-        typedef RawPtr<T> PassInType;
-        typedef RawPtr<T>* IteratorGetType;
-        typedef const RawPtr<T>* IteratorConstGetType;
-        typedef RawPtr<T>& IteratorReferenceType;
-        typedef T* const IteratorConstReferenceType;
-        static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { return *x; }
-        static IteratorConstReferenceType getToReferenceConstConversion(IteratorConstGetType x) { return x->get(); }
-        typedef RawPtr<T> PeekOutType;
-        typedef RawPtr<T> PassOutType;
-
-        template<typename U>
-        static void store(const U& value, RawPtr<T>& storage) { storage = value; }
-
-        static PeekOutType peek(const RawPtr<T>& value) { return value; }
-        static PeekOutType peek(std::nullptr_t) { return nullptr; }
-
-        static PassOutType passOut(const RawPtr<T>& value) { return value; }
-        static PassOutType passOut(std::nullptr_t) { return nullptr; }
-    };
+    template<typename T> struct HashTraits<RawPtr<T> > : HashTraits<T*> { };
 
     template<> struct HashTraits<String> : SimpleClassHashTraits<String> {
         static const bool hasIsEmptyValueFunction = true;
@@ -297,7 +275,7 @@ namespace WTF {
         struct NeedsTracingLazily {
             static const bool value = ShouldBeTraced<KeyTraits>::value || ShouldBeTraced<ValueTraits>::value;
         };
-        static const bool isWeak = KeyTraits::isWeak || ValueTraits::isWeak;
+        static const WeakHandlingFlag weakHandlingFlag = (KeyTraits::weakHandlingFlag == WeakHandlingInCollections || ValueTraits::weakHandlingFlag == WeakHandlingInCollections) ? WeakHandlingInCollections : NoWeakHandlingInCollections;
 
         static const unsigned minimumTableSize = KeyTraits::minimumTableSize;
 
@@ -314,6 +292,16 @@ namespace WTF {
         static T emptyValue() { return reinterpret_cast<T>(1); }
     };
 
+    // This is for tracing inside collections that have special support for weak
+    // pointers. The trait has a trace method which returns true if there are weak
+    // pointers to things that have not (yet) been marked live. Returning true
+    // indicates that the entry in the collection may yet be removed by weak
+    // handling. Default implementation for non-weak types is to use the regular
+    // non-weak TraceTrait. Default implementation for types with weakness is to
+    // call traceInCollection on the type's trait.
+    template<WeakHandlingFlag weakHandlingFlag, ShouldWeakPointersBeMarkedStrongly strongify, typename T, typename Traits>
+    struct TraceInCollectionTrait;
+
 } // namespace WTF
 
 using WTF::HashTraits;