Changeset 24059 in webkit for trunk/JavaScriptCore/wtf/HashSet.h


Ignore:
Timestamp:
Jul 6, 2007, 5:09:08 AM (18 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Antti.

  • <rdar://problem/5311093> JavaScriptCore fails to build with strict-aliasing warnings


  • Configurations/Base.xcconfig: Re-enable -Wstrict-aliasing
  • bindings/jni/jni_utility.cpp: (KJS::Bindings::getJNIEnv): Type-pun via a union instead of a pointer cast.
  • wtf/HashMap.h: (WTF::): Instead of doing type-punned assignments via pointer cast, do one of three things: (1) assign directly w/o cast if storage type matches real type; (2) assign using cast via union if type does not need reffing; (3) copy with memcpy and ref/deref manually if type needs reffing. This is ok peref-wise because memcpy of a constant length gets optomized. HashTraits are now expected to make ref()/deref() take the storage type, not the true type.
  • wtf/HashSet.h: (WTF::): Same basic idea.
  • wtf/HashTable.h: (WTF::): Added Assigner template for use by HashMap/HashSet. Change RefCounter to call ref() and deref() via storage type, avoiding the need to type-pun. (WTF::RefCounter::ref): ditto (WTF::RefCounter::deref): ditto
  • wtf/HashTraits.h: (WTF::): Change ref() and deref() for RefPtr HashTraits to take the storage type; cast via union to pointer type.
  • wtf/FastMalloc.cpp: (WTF::TCMalloc_PageHeap::init): Changed from constructor to init function so this can go in a union. (WTF::): redefine pageheap macro in terms of getPageHeap(). (WTF::getPageHeap): new inline function, helper for pageheap macro. This hides the cast in a union. (WTF::TCMalloc_ThreadCache::InitModule): Call init() instead of using placement new to initialize page heap.
  • wtf/TCPageMap.h: (TCMalloc_PageMap1::init): Changed from constructor to init function. (TCMalloc_PageMap2::init): ditto (TCMalloc_PageMap3::init): ditto

WebCore:

Reviewed by Antti.

  • <rdar://problem/5311093> JavaScriptCore fails to build with strict-aliasing warnings
  • platform/StringHash.h: (WTF::): Adapt to newer way to do storage types.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/HashSet.h

    r21494 r24059  
    103103    };
    104104
    105     template<bool canReplaceDeletedValue, typename ValueType, typename StorageTraits, typename HashFunctions>
     105    template<bool canReplaceDeletedValue, typename ValueType, typename ValueTraits, typename StorageTraits, typename HashFunctions>
    106106    struct HashSetTranslator;
    107107
    108     template<typename ValueType, typename StorageTraits, typename HashFunctions>
    109     struct HashSetTranslator<true, ValueType, StorageTraits, HashFunctions> {
     108    template<typename ValueType, typename ValueTraits, typename StorageTraits, typename HashFunctions>
     109    struct HashSetTranslator<true, ValueType, ValueTraits, StorageTraits, HashFunctions> {
    110110        typedef typename StorageTraits::TraitType StorageType;
    111111        static unsigned hash(const ValueType& key) { return HashFunctions::hash(key); }
     
    113113        static void translate(StorageType& location, const ValueType& key, const ValueType&, unsigned)
    114114        {
    115             *(ValueType*)&location = key;
     115            Assigner<ValueTraits::needsRef, ValueType, StorageType, ValueTraits>::assign(key, location);
    116116        }
    117117    };
    118118
    119     template<typename ValueType, typename StorageTraits, typename HashFunctions>
    120     struct HashSetTranslator<false, ValueType, StorageTraits, HashFunctions> {
     119    template<typename ValueType, typename ValueTraits, typename StorageTraits, typename HashFunctions>
     120    struct HashSetTranslator<false, ValueType, ValueTraits, StorageTraits, HashFunctions> {
    121121        typedef typename StorageTraits::TraitType StorageType;
    122122        static unsigned hash(const ValueType& key) { return HashFunctions::hash(key); }
     
    126126            if (location == StorageTraits::deletedValue())
    127127                location = StorageTraits::emptyValue();
    128             *(ValueType*)&location = key;
     128            Assigner<ValueTraits::needsRef, ValueType, StorageType, ValueTraits>::assign(key, location);
    129129        }
    130130    };
     
    265265    {
    266266        const bool canReplaceDeletedValue = !ValueTraits::needsDestruction || StorageTraits::needsDestruction;
    267         typedef HashSetTranslator<canReplaceDeletedValue, ValueType, StorageTraits, HashFunctions> Translator;
     267        typedef HashSetTranslator<canReplaceDeletedValue, ValueType, ValueTraits, StorageTraits, HashFunctions> Translator;
    268268        return m_impl.template add<ValueType, ValueType, Translator>(value, value);
    269269    }
Note: See TracChangeset for help on using the changeset viewer.