Changeset 118483 in webkit for trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
- Timestamp:
- May 24, 2012, 11:52:00 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
r115545 r118483 54 54 typedef HashMap<KeyType, WeakImpl*, HashArg, KeyTraitsArg> MapType; 55 55 typedef typename HandleTypes<MappedType>::ExternalType ExternalType; 56 typedef typename MapType::iterator map_iterator;57 56 58 57 public: 59 60 struct iterator {61 friend class WeakGCMap;62 iterator(map_iterator iter)63 : m_iterator(iter)64 {65 }66 67 std::pair<KeyType, ExternalType> get() const { return std::make_pair(m_iterator->first, HandleTypes<MappedType>::getFromSlot(const_cast<JSValue*>(&m_iterator->second->jsValue()))); }68 69 iterator& operator++() { ++m_iterator; return *this; }70 71 // postfix ++ intentionally omitted72 73 // Comparison.74 bool operator==(const iterator& other) const { return m_iterator == other.m_iterator; }75 bool operator!=(const iterator& other) const { return m_iterator != other.m_iterator; }76 77 private:78 map_iterator m_iterator;79 };80 81 typedef WTF::HashTableAddResult<iterator> AddResult;82 83 58 WeakGCMap() 84 59 { 85 60 } 86 61 87 bool isEmpty() { return m_map.isEmpty(); }88 62 void clear() 89 63 { 90 map_iterator end = m_map.end();91 for ( map_iterator ptr = m_map.begin(); ptr != end; ++ptr)64 typename MapType::iterator end = m_map.end(); 65 for (typename MapType::iterator ptr = m_map.begin(); ptr != end; ++ptr) 92 66 WeakSet::deallocate(ptr->second); 93 67 m_map.clear(); 94 }95 96 bool contains(const KeyType& key) const97 {98 return m_map.contains(key);99 }100 101 iterator find(const KeyType& key)102 {103 return m_map.find(key);104 }105 106 void remove(iterator iter)107 {108 ASSERT(iter.m_iterator != m_map.end());109 WeakImpl* impl = iter.m_iterator->second;110 ASSERT(impl);111 WeakSet::deallocate(impl);112 m_map.remove(iter.m_iterator);113 68 } 114 69 … … 116 71 { 117 72 return HandleTypes<MappedType>::getFromSlot(const_cast<JSValue*>(&m_map.get(key)->jsValue())); 118 }119 120 AddResult add(JSGlobalData&, const KeyType& key, ExternalType value)121 {122 typename MapType::AddResult result = m_map.add(key, 0);123 if (result.isNewEntry)124 result.iterator->second = WeakSet::allocate(value, this, FinalizerCallback::finalizerContextFor(key));125 126 // WeakGCMap exposes a different iterator, so we need to wrap it and create our own AddResult.127 return AddResult(iterator(result.iterator), result.isNewEntry);128 73 } 129 74 … … 136 81 } 137 82 138 ExternalType take(const KeyType& key)83 void remove(const KeyType& key) 139 84 { 140 85 WeakImpl* impl = m_map.take(key); 141 86 if (!impl) 142 return HashTraits<ExternalType>::emptyValue(); 143 ExternalType result = HandleTypes<MappedType>::getFromSlot(const_cast<JSValue*>(&impl->jsValue())); 87 return; 144 88 WeakSet::deallocate(impl); 145 return result;146 89 } 147 90 148 size_t size() { return m_map.size(); }149 150 iterator begin() { return iterator(m_map.begin()); }151 iterator end() { return iterator(m_map.end()); }152 153 91 ~WeakGCMap() 154 92 {
Note:
See TracChangeset
for help on using the changeset viewer.