From 2fc2651226baac27029e38c9d6ef883fa32084db Mon Sep 17 00:00:00 2001 From: Steve Block Date: Wed, 18 May 2011 13:36:51 +0100 Subject: Merge WebKit at r78450: Initial merge by git. Change-Id: I6d3e5f1f868ec266a0aafdef66182ddc3f265dc1 --- Source/JavaScriptCore/runtime/WeakGCMap.h | 60 ++++++++++++++++++------------- 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'Source/JavaScriptCore/runtime/WeakGCMap.h') 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::iterator iterator; - typedef typename HashMap::const_iterator const_iterator; + typedef typename HashMap >::iterator iterator; + typedef typename HashMap >::const_iterator const_iterator; bool isEmpty() { return m_map.isEmpty(); } void clear() { m_map.clear(); } - MappedType get(const KeyType& key) const; - pair set(const KeyType&, const MappedType&); - MappedType take(const KeyType& key); + MappedType* get(const KeyType&) const; + pair 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* 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 m_map; + HashMap > m_map; }; template -inline MappedType WeakGCMap::get(const KeyType& key) const +inline MappedType* WeakGCMap::get(const KeyType& key) const { - MappedType result = m_map.get(key); - if (result == HashTraits::emptyValue()) + MappedType* result = m_map.get(key).get(); + if (result == HashTraits::emptyValue()) return result; - if (!Heap::isCellMarked(result)) - return HashTraits::emptyValue(); + if (!Heap::isMarked(result)) + return HashTraits::emptyValue(); return result; } template -MappedType WeakGCMap::take(const KeyType& key) +MappedType* WeakGCMap::take(const KeyType& key) { - MappedType result = m_map.take(key); - if (result == HashTraits::emptyValue()) + MappedType* result = m_map.take(key).get(); + if (result == HashTraits::emptyValue()) return result; - if (!Heap::isCellMarked(result)) - return HashTraits::emptyValue(); + if (!Heap::isMarked(result)) + return HashTraits::emptyValue(); return result; } template -pair::iterator, bool> WeakGCMap::set(const KeyType& key, const MappedType& value) +pair::iterator, bool> WeakGCMap::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 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 -bool WeakGCMap::uncheckedRemove(const KeyType& key, const MappedType& value) +bool WeakGCMap::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; -- cgit v1.1