Changeset 77098 in webkit for trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
- Timestamp:
- Jan 30, 2011, 5:13:10 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
r77044 r77098 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(); } … … 70 77 const_iterator uncheckedEnd() const { return m_map.end(); } 71 78 72 bool isValid(iterator it) const { return Heap::isCellMarked(it->second ); }73 bool isValid(const_iterator it) const { return Heap::isCellMarked(it->second ); }79 bool isValid(iterator it) const { return Heap::isCellMarked(it->second.get()); } 80 bool isValid(const_iterator it) const { return Heap::isCellMarked(it->second.get()); } 74 81 75 82 private: 76 HashMap<KeyType, MappedType> m_map;83 HashMap<KeyType, DeprecatedPtr<MappedType> > m_map; 77 84 }; 78 85 79 86 template<typename KeyType, typename MappedType> 80 inline MappedType WeakGCMap<KeyType, MappedType>::get(const KeyType& key) const87 inline MappedType* WeakGCMap<KeyType, MappedType>::get(const KeyType& key) const 81 88 { 82 MappedType result = m_map.get(key);83 if (result == HashTraits<MappedType >::emptyValue())89 MappedType* result = m_map.get(key).get(); 90 if (result == HashTraits<MappedType*>::emptyValue()) 84 91 return result; 85 92 if (!Heap::isCellMarked(result)) 86 return HashTraits<MappedType >::emptyValue();93 return HashTraits<MappedType*>::emptyValue(); 87 94 return result; 88 95 } 89 96 90 97 template<typename KeyType, typename MappedType> 91 MappedType WeakGCMap<KeyType, MappedType>::take(const KeyType& key)98 MappedType* WeakGCMap<KeyType, MappedType>::take(const KeyType& key) 92 99 { 93 MappedType result = m_map.take(key);94 if (result == HashTraits<MappedType >::emptyValue())100 MappedType* result = m_map.take(key).get(); 101 if (result == HashTraits<MappedType*>::emptyValue()) 95 102 return result; 96 103 if (!Heap::isCellMarked(result)) 97 return HashTraits<MappedType >::emptyValue();104 return HashTraits<MappedType*>::emptyValue(); 98 105 return result; 99 106 } 100 107 101 108 template<typename KeyType, typename MappedType> 102 pair<typename HashMap<KeyType, MappedType>::iterator, bool> WeakGCMap<KeyType, MappedType>::set(const KeyType& key, const MappedType&value)109 pair<typename WeakGCMap<KeyType, MappedType>::iterator, bool> WeakGCMap<KeyType, MappedType>::set(const KeyType& key, MappedType* value) 103 110 { 104 111 Heap::markCell(value); // If value is newly allocated, it's not marked, so mark it now. 105 112 pair<iterator, bool> result = m_map.add(key, value); 106 113 if (!result.second) { // pre-existing entry 107 result.second = !Heap::isCellMarked(result.first->second );114 result.second = !Heap::isCellMarked(result.first->second.get()); 108 115 result.first->second = value; 109 116 } … … 112 119 113 120 template<typename KeyType, typename MappedType> 114 bool WeakGCMap<KeyType, MappedType>::uncheckedRemove(const KeyType& key, const MappedType&value)121 bool WeakGCMap<KeyType, MappedType>::uncheckedRemove(const KeyType& key, MappedType* value) 115 122 { 116 123 iterator it = m_map.find(key); 117 124 if (it == m_map.end()) 118 125 return false; 119 if (it->second != value)126 if (it->second.get() != value) 120 127 return false; 121 128 m_map.remove(it);
Note:
See TracChangeset
for help on using the changeset viewer.