Changeset 181297 in webkit for trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
- Timestamp:
- Mar 9, 2015, 5:09:39 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/WeakGCMap.h
r181214 r181297 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 }65 66 ALWAYS_INLINE AddResult add(const KeyType& key, ValueType value)67 {68 gcMapIfNeeded();69 AddResult addResult = m_map.fastAdd(key, nullptr);70 if (!addResult.iterator->value) { // New value or found a zombie value.71 addResult.isNewEntry = true;72 addResult.iterator->value = WTF::move(value);73 }74 return addResult;75 61 } 76 62 … … 104 90 } 105 91 92 void pruneStaleEntries(); 93 106 94 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 95 HashMapType m_map; 132 int m_gcThreshold;96 VM& m_vm; 133 97 }; 134 135 template<typename KeyArg, typename RawMappedArg, typename HashArg, typename KeyTraitsArg>136 const int WeakGCMap<KeyArg, RawMappedArg, HashArg, KeyTraitsArg>::minGCThreshold;137 98 138 99 } // namespace JSC
Note:
See TracChangeset
for help on using the changeset viewer.