summaryrefslogtreecommitdiffstats
path: root/Source/JavaScriptCore/runtime/WeakGCMap.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/runtime/WeakGCMap.h')
-rw-r--r--Source/JavaScriptCore/runtime/WeakGCMap.h60
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;