Changeset 83664 in webkit


Ignore:
Timestamp:
Apr 12, 2011 4:48:11 PM (13 years ago)
Author:
ggaren@apple.com
Message:

2011-04-12 Oliver Hunt <oliver@apple.com>

Reviewed by Geoffrey Garen.

Make API callback objects use weak handles to run their finalizers
https://bugs.webkit.org/show_bug.cgi?id=58389

Make the API object's private data struct act as a finalizer for
an api object if the callback object has a API defined finalizer.

  • API/JSCallbackObject.cpp: (JSC::JSCallbackObjectData::finalize):
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h: (JSC::::init):
  • heap/Handle.h:

2011-04-12 Geoffrey Garen <ggaren@apple.com>

Reviewed by Geoffrey Garen.

Cleaned up hash traits, and added hash traits for handles
https://bugs.webkit.org/show_bug.cgi?id=58381

  • dom/QualifiedName.h: Use new SimpleClassHashTraits to avoid duplication.
  • platform/KURL.h: (WebCore::KURL::KURL): (WebCore::KURL::isHashTableDeletedValue): Added explicit hash table deleted value constructor, to be more explicit and enable use of SimpleClassHashTraits.
  • platform/KURLHash.h: Use new SimpleClassHashTraits to avoid duplication.
  • platform/graphics/FontCache.cpp: Ditto.
  • platform/network/ProtectionSpaceHash.h: Ditto.
  • svg/properties/SVGAnimatedPropertyDescription.h: Ditto.
Location:
trunk/Source
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r83661 r83664  
    1515        (JSC::::init):
    1616        * heap/Handle.h:
     17
     182011-04-12  Geoffrey Garen  <ggaren@apple.com>
     19
     20        Reviewed by Geoffrey Garen.
     21
     22        Cleaned up hash traits, and added hash traits for handles
     23        https://bugs.webkit.org/show_bug.cgi?id=58381
     24
     25        * heap/Handle.h:
     26        (JSC::HandleBase::swap):
     27        (JSC::Handle::Handle):
     28        (JSC::Handle::swap): Implemented swap, so we can rehash efficiently, and
     29        without creating new handles (which is not allowed during handle finalization).
     30
     31        * heap/Strong.h:
     32        (JSC::Strong::swap): Use new SimpleClassHashTraits to avoid duplication.
     33
     34        * heap/Weak.h:
     35        (JSC::Weak::isHashTableDeletedValue):
     36        (JSC::Weak::Weak):
     37        (JSC::Weak::swap):
     38        (JSC::Weak::hashTableDeletedValue): Ditto.
     39
     40        * wtf/HashTraits.h:
     41        (WTF::SimpleClassHashTraits::constructDeletedValue):
     42        (WTF::SimpleClassHashTraits::isDeletedValue): Added SimpleClassHashTraits,
     43        which are analogous to SimpleClassVectorTraits, since they are used in a
     44        bunch of places.
     45
     46        * wtf/RetainPtr.h: Use new SimpleClassHashTraits to avoid duplication.
     47
     48        * wtf/text/StringHash.h: Use new SimpleClassHashTraits to avoid duplication.
    1749
    18502011-04-12  Geoffrey Garen  <ggaren@apple.com>
  • trunk/Source/JavaScriptCore/heap/Handle.h

    r83661 r83664  
    6161    {
    6262    }
     63   
     64    void swap(HandleBase& other) { std::swap(m_slot, other.m_slot); }
    6365
    6466    HandleSlot slot() const { return m_slot; }
     
    142144    {
    143145        typename HandleTypes<T>::template validateUpcast<U>();
    144         m_slot = o.slot();
    145     }
     146        setSlot(o.slot());
     147    }
     148
     149    void swap(Handle& other) { HandleBase::swap(other); }
    146150
    147151    ExternalType get() const { return HandleTypes<T>::getFromSlot(this->slot()); }
  • trunk/Source/JavaScriptCore/heap/Strong.h

    r83637 r83664  
    8989    }
    9090
     91    void swap(Strong& other)
     92    {
     93        Handle<T>::swap(other);
     94    }
     95
    9196    void set(JSGlobalData& globalData, ExternalType value)
    9297    {
     
    146151};
    147152
    148 template<typename P> struct HashTraits<JSC::Strong<P> > : GenericHashTraits<JSC::Strong<P> > {
    149     static const bool emptyValueIsZero = true;
    150     static JSC::Strong<P> emptyValue() { return JSC::Strong<P>(); }
    151     static void constructDeletedValue(JSC::Strong<P>& slot) { new (&slot) JSC::Strong<P>(JSC::Strong<P>::HashTableDeletedValue); }
    152     static bool isDeletedValue(const JSC::Strong<P>& value) { return value.isHashTableDeletedValue(); }
    153 };
     153template<typename P> struct HashTraits<JSC::Strong<P> > : SimpleClassHashTraits<JSC::Strong<P> > { };
    154154
    155155}
  • trunk/Source/JavaScriptCore/heap/Weak.h

    r83637 r83664  
    7272    }
    7373   
     74    enum HashTableDeletedValueTag { HashTableDeletedValue };
     75    bool isHashTableDeletedValue() const { return slot() == hashTableDeletedValue(); }
     76    Weak(HashTableDeletedValueTag)
     77        : Handle<T>(hashTableDeletedValue())
     78    {
     79    }
     80
    7481    ~Weak()
    7582    {
    7683        clear();
     84    }
     85
     86    void swap(Weak& other)
     87    {
     88        Handle<T>::swap(other);
    7789    }
    7890
     
    98110
    99111private:
     112    static HandleSlot hashTableDeletedValue() { return reinterpret_cast<HandleSlot>(-1); }
     113
    100114    void set(ExternalType externalType)
    101115    {
     
    115129};
    116130
     131template<typename P> struct HashTraits<JSC::Weak<P> > : SimpleClassHashTraits<JSC::Weak<P> > { };
     132
    117133}
    118134
  • trunk/Source/JavaScriptCore/wtf/HashTraits.h

    r54618 r83664  
    8282    };
    8383
    84     template<typename P> struct HashTraits<RefPtr<P> > : GenericHashTraits<RefPtr<P> > {
     84    template<typename T> struct SimpleClassHashTraits : GenericHashTraits<T> {
    8585        static const bool emptyValueIsZero = true;
    86         static void constructDeletedValue(RefPtr<P>& slot) { new (&slot) RefPtr<P>(HashTableDeletedValue); }
    87         static bool isDeletedValue(const RefPtr<P>& value) { return value.isHashTableDeletedValue(); }
     86        static void constructDeletedValue(T& slot) { new (&slot) T(HashTableDeletedValue); }
     87        static bool isDeletedValue(const T& value) { return value.isHashTableDeletedValue(); }
    8888    };
     89
     90    template<typename P> struct HashTraits<RefPtr<P> > : SimpleClassHashTraits<RefPtr<P> > { };
    8991
    9092    // special traits for pairs, helpful for their use in HashMap implementation
  • trunk/Source/JavaScriptCore/wtf/RetainPtr.h

    r79434 r83664  
    235235    }
    236236   
    237     template<typename P> struct HashTraits<RetainPtr<P> > : GenericHashTraits<RetainPtr<P> > {
    238         static const bool emptyValueIsZero = true;
    239         static void constructDeletedValue(RetainPtr<P>& slot) { new (&slot) RetainPtr<P>(HashTableDeletedValue); }
    240         static bool isDeletedValue(const RetainPtr<P>& value) { return value == reinterpret_cast<P*>(-1); }
    241     };
     237    template<typename P> struct HashTraits<RetainPtr<P> > : SimpleClassHashTraits<RetainPtr<P> > { };
    242238   
    243239    template<typename P> struct PtrHash<RetainPtr<P> > : PtrHash<P*> {
  • trunk/Source/JavaScriptCore/wtf/text/StringHash.h

    r81548 r83664  
    180180    };
    181181
    182     template<> struct HashTraits<String> : GenericHashTraits<String> {
    183         static const bool emptyValueIsZero = true;
    184         static void constructDeletedValue(String& slot) { new (&slot) String(HashTableDeletedValue); }
    185         static bool isDeletedValue(const String& slot) { return slot.isHashTableDeletedValue(); }
    186     };
     182    template<> struct HashTraits<String> : SimpleClassHashTraits<String> { };
    187183
    188184}
  • trunk/Source/WebCore/ChangeLog

    r83659 r83664  
     12011-04-12  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Cleaned up hash traits, and added hash traits for handles
     6        https://bugs.webkit.org/show_bug.cgi?id=58381
     7
     8        * dom/QualifiedName.h: Use new SimpleClassHashTraits to avoid duplication.
     9
     10        * platform/KURL.h:
     11        (WebCore::KURL::KURL):
     12        (WebCore::KURL::isHashTableDeletedValue): Added explicit hash table
     13        deleted value constructor, to be more explicit and enable use of
     14        SimpleClassHashTraits.
     15
     16        * platform/KURLHash.h: Use new SimpleClassHashTraits to avoid duplication.
     17
     18        * platform/graphics/FontCache.cpp: Ditto.
     19        * platform/network/ProtectionSpaceHash.h: Ditto.
     20        * svg/properties/SVGAnimatedPropertyDescription.h: Ditto.
     21
    1222011-04-12  Luiz Agostini  <luiz.agostini@openbossa.org>
    223
  • trunk/Source/WebCore/dom/QualifiedName.h

    r81548 r83664  
    142142    };
    143143   
    144     template<> struct HashTraits<WebCore::QualifiedName> : GenericHashTraits<WebCore::QualifiedName> {
     144    template<> struct HashTraits<WebCore::QualifiedName> : SimpleClassHashTraits<WebCore::QualifiedName> {
    145145        static const bool emptyValueIsZero = false;
    146146        static WebCore::QualifiedName emptyValue() { return WebCore::QualifiedName(nullAtom, nullAtom, nullAtom); }
    147         static void constructDeletedValue(WebCore::QualifiedName& slot) { new (&slot) WebCore::QualifiedName(WTF::HashTableDeletedValue); }
    148         static bool isDeletedValue(const WebCore::QualifiedName& slot) { return slot.isHashTableDeletedValue(); }
    149147    };
    150148}
  • trunk/Source/WebCore/platform/KURL.h

    r80566 r83664  
    7777    KURL(ParsedURLStringTag, const String&);
    7878    KURL(ParsedURLStringTag, const URLString&);
     79    KURL(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDeletedValue) { }
     80    bool isHashTableDeletedValue() const { return m_string.isHashTableDeletedValue(); }
    7981
    8082    // Resolves the relative URL with the given base URL. If provided, the
  • trunk/Source/WebCore/platform/KURLHash.h

    r65077 r83664  
    5151namespace WTF {
    5252
    53     template<> struct HashTraits<WebCore::KURL> : GenericHashTraits<WebCore::KURL> {
    54         static const bool emptyValueIsZero = true;
    55         static void constructDeletedValue(WebCore::KURL& slot) { new (&slot) WebCore::KURL(WebCore::ParsedURLString, WTF::String(HashTableDeletedValue)); }
    56         static bool isDeletedValue(const WebCore::KURL& slot) { return slot.string().isHashTableDeletedValue(); }
    57     };
     53    template<> struct HashTraits<WebCore::KURL> : SimpleClassHashTraits<WebCore::KURL> { };
    5854
    5955} // namespace WTF
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r81548 r83664  
    122122};
    123123
    124 struct FontPlatformDataCacheKeyTraits : WTF::GenericHashTraits<FontPlatformDataCacheKey> {
    125     static const bool emptyValueIsZero = true;
    126     static const FontPlatformDataCacheKey& emptyValue()
    127     {
    128         DEFINE_STATIC_LOCAL(FontPlatformDataCacheKey, key, (nullAtom));
    129         return key;
    130     }
    131     static void constructDeletedValue(FontPlatformDataCacheKey& slot)
    132     {
    133         new (&slot) FontPlatformDataCacheKey(HashTableDeletedValue);
    134     }
    135     static bool isDeletedValue(const FontPlatformDataCacheKey& value)
    136     {
    137         return value.isHashTableDeletedValue();
    138     }
    139 };
     124struct FontPlatformDataCacheKeyTraits : WTF::SimpleClassHashTraits<FontPlatformDataCacheKey> { };
    140125
    141126typedef HashMap<FontPlatformDataCacheKey, FontPlatformData*, FontPlatformDataCacheKeyHash, FontPlatformDataCacheKeyTraits> FontPlatformDataCache;
  • trunk/Source/WebCore/platform/network/ProtectionSpaceHash.h

    r81548 r83664  
    5858namespace WTF {
    5959
    60     // WebCore::ProtectionSpaceHash is the default hash for ProtectionSpace
    61     template<> struct HashTraits<WebCore::ProtectionSpace> : GenericHashTraits<WebCore::ProtectionSpace> {
    62         static const bool emptyValueIsZero = true;
    63         static void constructDeletedValue(WebCore::ProtectionSpace& slot) { new (&slot) WebCore::ProtectionSpace(HashTableDeletedValue); }
    64         static bool isDeletedValue(const WebCore::ProtectionSpace& slot) { return slot.isHashTableDeletedValue(); }
    65     };
     60    template<> struct HashTraits<WebCore::ProtectionSpace> : SimpleClassHashTraits<WebCore::ProtectionSpace> { };
    6661
    6762    template<typename T> struct DefaultHash;
  • trunk/Source/WebCore/svg/properties/SVGAnimatedPropertyDescription.h

    r81548 r83664  
    8181};
    8282
    83 struct SVGAnimatedPropertyDescriptionHashTraits : WTF::GenericHashTraits<SVGAnimatedPropertyDescription> {
    84     static const bool emptyValueIsZero = true;
    85 
    86     static void constructDeletedValue(SVGAnimatedPropertyDescription& slot)
    87     {
    88         new (&slot) SVGAnimatedPropertyDescription(WTF::HashTableDeletedValue);
    89     }
    90 
    91     static bool isDeletedValue(const SVGAnimatedPropertyDescription& value)
    92     {
    93         return value.isHashTableDeletedValue();
    94     }
    95 };
     83struct SVGAnimatedPropertyDescriptionHashTraits : WTF::SimpleClassHashTraits<SVGAnimatedPropertyDescription> { };
    9684 
    9785}
Note: See TracChangeset for help on using the changeset viewer.