Changeset 24059 in webkit for trunk/JavaScriptCore/wtf/HashTable.h
- Timestamp:
- Jul 6, 2007, 5:09:08 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/HashTable.h
r19302 r24059 851 851 }; 852 852 853 template<bool needsRef, typename ValueTraits > struct RefCounterBase;854 855 template<typename ValueTraits >856 struct RefCounterBase<false, ValueTraits > {857 typedef typename Value Traits::TraitType ValueType;858 static void ref(const Value Type&) { }859 static void deref(const Value Type&) { }860 }; 861 862 template<typename ValueTraits >863 struct RefCounterBase<true, ValueTraits > {864 typedef typename Value Traits::TraitType ValueType;865 static void ref(const Value Type& v) { ValueTraits::ref(*(const ValueType*)&v); }866 static void deref(const Value Type& v) { ValueTraits::deref(*(const ValueType*)&v); }853 template<bool needsRef, typename ValueTraits, typename ValueStorageTraits> struct RefCounterBase; 854 855 template<typename ValueTraits, typename ValueStorageTraits> 856 struct RefCounterBase<false, ValueTraits, ValueStorageTraits> { 857 typedef typename ValueStorageTraits::TraitType ValueStorageType; 858 static void ref(const ValueStorageType&) { } 859 static void deref(const ValueStorageType&) { } 860 }; 861 862 template<typename ValueTraits, typename ValueStorageTraits> 863 struct RefCounterBase<true, ValueTraits, ValueStorageTraits> { 864 typedef typename ValueStorageTraits::TraitType ValueStorageType; 865 static void ref(const ValueStorageType& v) { ValueTraits::ref(v); } 866 static void deref(const ValueStorageType& v) { ValueTraits::deref(v); } 867 867 }; 868 868 … … 871 871 typedef typename ValueStorageTraits::TraitType ValueStorageType; 872 872 static const bool needsRef = NeedsRef<ValueTraits, ValueStorageTraits>::value; 873 typedef RefCounterBase<needsRef, ValueTraits > Base;874 static void ref(const ValueStorageType& v) { Base::ref( *(const ValueType*)&v); }875 static void deref(const ValueStorageType& v) { Base::deref( *(const ValueType*)&v); }873 typedef RefCounterBase<needsRef, ValueTraits, ValueStorageTraits> Base; 874 static void ref(const ValueStorageType& v) { Base::ref(v); } 875 static void deref(const ValueStorageType& v) { Base::deref(v); } 876 876 }; 877 877 … … 885 885 static const bool firstNeedsRef = NeedsRef<FirstTraits, FirstStorageTraits>::value; 886 886 static const bool secondNeedsRef = NeedsRef<SecondTraits, SecondStorageTraits>::value; 887 typedef RefCounterBase<firstNeedsRef, FirstTraits > FirstBase;888 typedef RefCounterBase<secondNeedsRef, SecondTraits > SecondBase;887 typedef RefCounterBase<firstNeedsRef, FirstTraits, FirstStorageTraits> FirstBase; 888 typedef RefCounterBase<secondNeedsRef, SecondTraits, SecondStorageTraits> SecondBase; 889 889 static void ref(const ValueStorageType& v) { 890 FirstBase::ref( *(const FirstType*)&v.first);891 SecondBase::ref( *(const SecondType*)&v.second);890 FirstBase::ref(v.first); 891 SecondBase::ref(v.second); 892 892 } 893 893 static void deref(const ValueStorageType& v) { 894 FirstBase::deref( *(const FirstType*)&v.first);895 SecondBase::deref( *(const SecondType*)&v.second);894 FirstBase::deref(v.first); 895 SecondBase::deref(v.second); 896 896 } 897 897 }; … … 938 938 }; 939 939 940 // helper template for HashMap and HashSet. 941 template<bool needsRef, typename FromType, typename ToType, typename FromTraits> struct Assigner; 942 943 template<typename FromType, typename ToType, typename FromTraits> struct Assigner<false, FromType, ToType, FromTraits> { 944 typedef union { 945 FromType m_from; 946 ToType m_to; 947 } UnionType; 948 949 static void assign(const FromType& from, ToType& to) { reinterpret_cast<UnionType*>(&to)->m_from = from; } 950 }; 951 952 template<typename FromType, typename ToType, typename FromTraits> struct Assigner<true, FromType, ToType, FromTraits> { 953 static void assign(const FromType& from, ToType& to) 954 { 955 ToType oldTo = to; 956 memcpy(&to, &from, sizeof(FromType)); 957 FromTraits::ref(to); 958 FromTraits::deref(oldTo); 959 } 960 }; 961 962 template<typename FromType, typename FromTraits> struct Assigner<false, FromType, FromType, FromTraits> { 963 static void assign(const FromType& from, FromType& to) { to = from; } 964 }; 965 966 template<typename FromType, typename FromTraits> struct Assigner<true, FromType, FromType, FromTraits> { 967 static void assign(const FromType& from, FromType& to) { to = from; } 968 }; 969 940 970 } // namespace WTF 941 971
Note:
See TracChangeset
for help on using the changeset viewer.