Changeset 181214 in webkit for trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
- Timestamp:
- Mar 7, 2015, 2:20:54 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
r181010 r181214 1 1 /* 2 * Copyright (C) 2009 , 2015Apple Inc. All rights reserved.2 * Copyright (C) 2009 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 explicit WeakGCMap(VM&); 51 ~WeakGCMap(); 50 WeakGCMap() 51 : m_gcThreshold(minGCThreshold) 52 { 53 } 52 54 53 55 ValueArg* get(const KeyType& key) const … … 58 60 AddResult set(const KeyType& key, ValueType value) 59 61 { 62 gcMapIfNeeded(); 60 63 return m_map.set(key, WTF::move(value)); 61 64 } … … 63 66 ALWAYS_INLINE AddResult add(const KeyType& key, ValueType value) 64 67 { 68 gcMapIfNeeded(); 65 69 AddResult addResult = m_map.fastAdd(key, nullptr); 66 70 if (!addResult.iterator->value) { // New value or found a zombie value. … … 100 104 } 101 105 102 void pruneStaleEntries(); 106 private: 107 static const int minGCThreshold = 3; 103 108 104 private: 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 105 131 HashMapType m_map; 106 VM& m_vm;132 int m_gcThreshold; 107 133 }; 134 135 template<typename KeyArg, typename RawMappedArg, typename HashArg, typename KeyTraitsArg> 136 const int WeakGCMap<KeyArg, RawMappedArg, HashArg, KeyTraitsArg>::minGCThreshold; 108 137 109 138 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.