Changeset 77151 in webkit for trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
- Timestamp:
- Jan 31, 2011, 12:07:21 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
r77125 r77151 47 47 48 48 public: 49 typedef typename HashMap<KeyType, MappedType>::iterator iterator;50 typedef typename HashMap<KeyType, MappedType>::const_iterator const_iterator;49 typedef typename HashMap<KeyType, DeprecatedPtr<MappedType> >::iterator iterator; 50 typedef typename HashMap<KeyType, DeprecatedPtr<MappedType> >::const_iterator const_iterator; 51 51 52 52 bool isEmpty() { return m_map.isEmpty(); } 53 53 void clear() { m_map.clear(); } 54 54 55 MappedType get(const KeyType& key) const;56 pair<iterator, bool> set(const KeyType&, const MappedType&);57 MappedType take(const KeyType& key);55 MappedType* get(const KeyType&) const; 56 pair<iterator, bool> set(const KeyType&, MappedType*); 57 MappedType* take(const KeyType&); 58 58 59 59 // These unchecked functions provide access to a value even if the value's … … 61 61 // during the GC mark phase, which begins by clearing all mark bits. 62 62 63 MappedType uncheckedGet(const KeyType& key) const { return m_map.get(key); } 64 bool uncheckedRemove(const KeyType&, const MappedType&); 63 MappedType* uncheckedGet(const KeyType& key) const { return m_map.get(key).get(); } 64 DeprecatedPtr<MappedType>* uncheckedGetSlot(const KeyType& key) 65 { 66 iterator iter = m_map.find(key); 67 if (iter == m_map.end()) 68 return 0; 69 return &iter->second; 70 } 71 bool uncheckedRemove(const KeyType&, MappedType*); 65 72 66 73 iterator uncheckedBegin() { return m_map.begin(); } … … 71 78 72 79 private: 73 HashMap<KeyType, MappedType> m_map;80 HashMap<KeyType, DeprecatedPtr<MappedType> > m_map; 74 81 }; 75 82 76 83 template<typename KeyType, typename MappedType> 77 inline MappedType WeakGCMap<KeyType, MappedType>::get(const KeyType& key) const84 inline MappedType* WeakGCMap<KeyType, MappedType>::get(const KeyType& key) const 78 85 { 79 MappedType result = m_map.get(key);80 if (result == HashTraits<MappedType >::emptyValue())86 MappedType* result = m_map.get(key).get(); 87 if (result == HashTraits<MappedType*>::emptyValue()) 81 88 return result; 82 89 if (!Heap::isCellMarked(result)) 83 return HashTraits<MappedType >::emptyValue();90 return HashTraits<MappedType*>::emptyValue(); 84 91 return result; 85 92 } 86 93 87 94 template<typename KeyType, typename MappedType> 88 MappedType WeakGCMap<KeyType, MappedType>::take(const KeyType& key)95 MappedType* WeakGCMap<KeyType, MappedType>::take(const KeyType& key) 89 96 { 90 MappedType result = m_map.take(key);91 if (result == HashTraits<MappedType >::emptyValue())97 MappedType* result = m_map.take(key).get(); 98 if (result == HashTraits<MappedType*>::emptyValue()) 92 99 return result; 93 100 if (!Heap::isCellMarked(result)) 94 return HashTraits<MappedType >::emptyValue();101 return HashTraits<MappedType*>::emptyValue(); 95 102 return result; 96 103 } 97 104 98 105 template<typename KeyType, typename MappedType> 99 pair<typename HashMap<KeyType, MappedType>::iterator, bool> WeakGCMap<KeyType, MappedType>::set(const KeyType& key, const MappedType&value)106 pair<typename WeakGCMap<KeyType, MappedType>::iterator, bool> WeakGCMap<KeyType, MappedType>::set(const KeyType& key, MappedType* value) 100 107 { 101 108 Heap::markCell(value); // If value is newly allocated, it's not marked, so mark it now. 102 109 pair<iterator, bool> result = m_map.add(key, value); 103 110 if (!result.second) { // pre-existing entry 104 result.second = !Heap::isCellMarked(result.first->second );111 result.second = !Heap::isCellMarked(result.first->second.get()); 105 112 result.first->second = value; 106 113 } … … 109 116 110 117 template<typename KeyType, typename MappedType> 111 bool WeakGCMap<KeyType, MappedType>::uncheckedRemove(const KeyType& key, const MappedType&value)118 bool WeakGCMap<KeyType, MappedType>::uncheckedRemove(const KeyType& key, MappedType* value) 112 119 { 113 120 iterator it = m_map.find(key); 114 121 if (it == m_map.end()) 115 122 return false; 116 if (it->second != value)123 if (it->second.get() != value) 117 124 return false; 118 125 m_map.remove(it);
Note:
See TracChangeset
for help on using the changeset viewer.