Changeset 181010 in webkit for trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
- Timestamp:
- Mar 4, 2015, 12:00:00 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
r170774 r181010 1 1 /* 2 * Copyright (C) 2009 Apple Inc. All rights reserved.2 * Copyright (C) 2009, 2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 48 48 typedef typename HashMapType::const_iterator const_iterator; 49 49 50 WeakGCMap() 51 : m_gcThreshold(minGCThreshold) 52 { 53 } 50 explicit WeakGCMap(VM&); 51 ~WeakGCMap(); 54 52 55 53 ValueArg* get(const KeyType& key) const … … 60 58 AddResult set(const KeyType& key, ValueType value) 61 59 { 62 gcMapIfNeeded();63 60 return m_map.set(key, WTF::move(value)); 64 61 } … … 66 63 ALWAYS_INLINE AddResult add(const KeyType& key, ValueType value) 67 64 { 68 gcMapIfNeeded();69 65 AddResult addResult = m_map.fastAdd(key, nullptr); 70 66 if (!addResult.iterator->value) { // New value or found a zombie value. … … 104 100 } 105 101 102 void pruneStaleEntries(); 103 106 104 private: 107 static const int minGCThreshold = 3;108 109 NEVER_INLINE void gcMap()110 {111 Vector<KeyType, 4> zombies;112 113 for (iterator it = m_map.begin(), end = m_map.end(); it != end; ++it) {114 if (!it->value)115 zombies.append(it->key);116 }117 118 for (size_t i = 0; i < zombies.size(); ++i)119 m_map.remove(zombies[i]);120 }121 122 void gcMapIfNeeded()123 {124 if (m_map.size() < m_gcThreshold)125 return;126 127 gcMap();128 m_gcThreshold = std::max(minGCThreshold, m_map.size() * 2 - 1);129 }130 131 105 HashMapType m_map; 132 int m_gcThreshold;106 VM& m_vm; 133 107 }; 134 135 template<typename KeyArg, typename RawMappedArg, typename HashArg, typename KeyTraitsArg>136 const int WeakGCMap<KeyArg, RawMappedArg, HashArg, KeyTraitsArg>::minGCThreshold;137 108 138 109 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.