diff options
author | Steve Block <steveblock@google.com> | 2011-05-18 13:36:51 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-05-24 15:38:28 +0100 |
commit | 2fc2651226baac27029e38c9d6ef883fa32084db (patch) | |
tree | e396d4bf89dcce6ed02071be66212495b1df1dec /Source/JavaScriptCore/runtime/WeakGCMap.h | |
parent | b3725cedeb43722b3b175aaeff70552e562d2c94 (diff) | |
download | external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.zip external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.tar.gz external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.tar.bz2 |
Merge WebKit at r78450: Initial merge by git.
Change-Id: I6d3e5f1f868ec266a0aafdef66182ddc3f265dc1
Diffstat (limited to 'Source/JavaScriptCore/runtime/WeakGCMap.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/WeakGCMap.h | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/Source/JavaScriptCore/runtime/WeakGCMap.h b/Source/JavaScriptCore/runtime/WeakGCMap.h index 316794f..7bf4503 100644 --- a/Source/JavaScriptCore/runtime/WeakGCMap.h +++ b/Source/JavaScriptCore/runtime/WeakGCMap.h @@ -46,22 +46,31 @@ class WeakGCMap { */ public: - typedef typename HashMap<KeyType, MappedType>::iterator iterator; - typedef typename HashMap<KeyType, MappedType>::const_iterator const_iterator; + typedef typename HashMap<KeyType, DeprecatedPtr<MappedType> >::iterator iterator; + typedef typename HashMap<KeyType, DeprecatedPtr<MappedType> >::const_iterator const_iterator; bool isEmpty() { return m_map.isEmpty(); } void clear() { m_map.clear(); } - MappedType get(const KeyType& key) const; - pair<iterator, bool> set(const KeyType&, const MappedType&); - MappedType take(const KeyType& key); + MappedType* get(const KeyType&) const; + pair<iterator, bool> set(const KeyType&, MappedType*); + MappedType* take(const KeyType&); // These unchecked functions provide access to a value even if the value's // mark bit is not set. This is used, among other things, to retrieve values // during the GC mark phase, which begins by clearing all mark bits. - - MappedType uncheckedGet(const KeyType& key) const { return m_map.get(key); } - bool uncheckedRemove(const KeyType&, const MappedType&); + + size_t uncheckedSize() { return m_map.size(); } + + MappedType* uncheckedGet(const KeyType& key) const { return m_map.get(key).get(); } + DeprecatedPtr<MappedType>* uncheckedGetSlot(const KeyType& key) + { + iterator iter = m_map.find(key); + if (iter == m_map.end()) + return 0; + return &iter->second; + } + bool uncheckedRemove(const KeyType&, MappedType*); iterator uncheckedBegin() { return m_map.begin(); } iterator uncheckedEnd() { return m_map.end(); } @@ -69,51 +78,54 @@ public: const_iterator uncheckedBegin() const { return m_map.begin(); } const_iterator uncheckedEnd() const { return m_map.end(); } + bool isValid(iterator it) const { return Heap::isMarked(it->second.get()); } + bool isValid(const_iterator it) const { return Heap::isMarked(it->second.get()); } + private: - HashMap<KeyType, MappedType> m_map; + HashMap<KeyType, DeprecatedPtr<MappedType> > m_map; }; template<typename KeyType, typename MappedType> -inline MappedType WeakGCMap<KeyType, MappedType>::get(const KeyType& key) const +inline MappedType* WeakGCMap<KeyType, MappedType>::get(const KeyType& key) const { - MappedType result = m_map.get(key); - if (result == HashTraits<MappedType>::emptyValue()) + MappedType* result = m_map.get(key).get(); + if (result == HashTraits<MappedType*>::emptyValue()) return result; - if (!Heap::isCellMarked(result)) - return HashTraits<MappedType>::emptyValue(); + if (!Heap::isMarked(result)) + return HashTraits<MappedType*>::emptyValue(); return result; } template<typename KeyType, typename MappedType> -MappedType WeakGCMap<KeyType, MappedType>::take(const KeyType& key) +MappedType* WeakGCMap<KeyType, MappedType>::take(const KeyType& key) { - MappedType result = m_map.take(key); - if (result == HashTraits<MappedType>::emptyValue()) + MappedType* result = m_map.take(key).get(); + if (result == HashTraits<MappedType*>::emptyValue()) return result; - if (!Heap::isCellMarked(result)) - return HashTraits<MappedType>::emptyValue(); + if (!Heap::isMarked(result)) + return HashTraits<MappedType*>::emptyValue(); return result; } template<typename KeyType, typename MappedType> -pair<typename HashMap<KeyType, MappedType>::iterator, bool> WeakGCMap<KeyType, MappedType>::set(const KeyType& key, const MappedType& value) +pair<typename WeakGCMap<KeyType, MappedType>::iterator, bool> WeakGCMap<KeyType, MappedType>::set(const KeyType& key, MappedType* value) { - Heap::markCell(value); // If value is newly allocated, it's not marked, so mark it now. + Heap::setMarked(value); // If value is newly allocated, it's not marked, so mark it now. pair<iterator, bool> result = m_map.add(key, value); if (!result.second) { // pre-existing entry - result.second = !Heap::isCellMarked(result.first->second); + result.second = !Heap::isMarked(result.first->second.get()); result.first->second = value; } return result; } template<typename KeyType, typename MappedType> -bool WeakGCMap<KeyType, MappedType>::uncheckedRemove(const KeyType& key, const MappedType& value) +bool WeakGCMap<KeyType, MappedType>::uncheckedRemove(const KeyType& key, MappedType* value) { iterator it = m_map.find(key); if (it == m_map.end()) return false; - if (it->second != value) + if (it->second.get() != value) return false; m_map.remove(it); return true; |