Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: third_party/WebKit/Source/wtf/HashCountedSet.h

Issue 2045883002: Clean up markClientsAndObserversFinished(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 iterator find(const ValueType& value) { return m_impl.find(value); } 64 iterator find(const ValueType& value) { return m_impl.find(value); }
65 const_iterator find(const ValueType& value) const { return m_impl.find(value ); } 65 const_iterator find(const ValueType& value) const { return m_impl.find(value ); }
66 bool contains(const ValueType& value ) const { return m_impl.contains(value) ; } 66 bool contains(const ValueType& value ) const { return m_impl.contains(value) ; }
67 unsigned count(const ValueType& value ) const { return m_impl.get(value); } 67 unsigned count(const ValueType& value ) const { return m_impl.get(value); }
68 68
69 // Increases the count if an equal value is already present the return value 69 // Increases the count if an equal value is already present the return value
70 // is a pair of an iterator to the new value's location, and a bool that is 70 // is a pair of an iterator to the new value's location, and a bool that is
71 // true if an new entry was added. 71 // true if an new entry was added.
72 AddResult add(const ValueType&); 72 AddResult add(const ValueType&);
73 73
74 // Generalized add(), adding the value N times.
75 AddResult add(const ValueType&, unsigned);
76
74 // Reduces the count of the value, and removes it if count goes down to 77 // Reduces the count of the value, and removes it if count goes down to
75 // zero, returns true if the value is removed. 78 // zero, returns true if the value is removed.
76 bool remove(const ValueType& value) { return remove(find(value)); } 79 bool remove(const ValueType& value) { return remove(find(value)); }
77 bool remove(iterator); 80 bool remove(iterator);
78 81
79 // Removes the value, regardless of its count. 82 // Removes the value, regardless of its count.
80 void removeAll(const ValueType& value) { removeAll(find(value)); } 83 void removeAll(const ValueType& value) { removeAll(find(value)); }
81 void removeAll(iterator); 84 void removeAll(iterator);
82 85
83 // Clears the whole set. 86 // Clears the whole set.
84 void clear() { m_impl.clear(); } 87 void clear() { m_impl.clear(); }
85 88
86 template <typename VisitorDispatcher> 89 template <typename VisitorDispatcher>
87 void trace(VisitorDispatcher visitor) { m_impl.trace(visitor); } 90 void trace(VisitorDispatcher visitor) { m_impl.trace(visitor); }
88 91
89 private: 92 private:
90 ImplType m_impl; 93 ImplType m_impl;
91 }; 94 };
92 95
93 template <typename T, typename U, typename V, typename W> 96 template <typename T, typename U, typename V, typename W>
94 inline typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V, W> ::add(const ValueType& value) 97 inline typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V, W> ::add(const ValueType& value)
95 { 98 {
96 AddResult result = m_impl.add(value, 0); 99 AddResult result = m_impl.add(value, 0);
97 ++result.storedValue->value; 100 ++result.storedValue->value;
98 return result; 101 return result;
99 } 102 }
100 103
101 template <typename T, typename U, typename V, typename W> 104 template <typename T, typename U, typename V, typename W>
105 inline typename HashCountedSet<T, U, V, W>::AddResult HashCountedSet<T, U, V, W> ::add(const ValueType& value, unsigned count)
106 {
107 DCHECK_GT(count, 0);
108 AddResult result = m_impl.add(value, 0);
109 result.storedValue->value += count;
110 return result;
111 }
112
113 template <typename T, typename U, typename V, typename W>
102 inline bool HashCountedSet<T, U, V, W>::remove(iterator it) 114 inline bool HashCountedSet<T, U, V, W>::remove(iterator it)
103 { 115 {
104 if (it == end()) 116 if (it == end())
105 return false; 117 return false;
106 118
107 unsigned oldVal = it->value; 119 unsigned oldVal = it->value;
108 ASSERT(oldVal); 120 ASSERT(oldVal);
109 unsigned newVal = oldVal - 1; 121 unsigned newVal = oldVal - 1;
110 if (newVal) { 122 if (newVal) {
111 it->value = newVal; 123 it->value = newVal;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 iterator end = collection.end(); 169 iterator end = collection.end();
158 for (unsigned i = 0; it != end; ++it, ++i) 170 for (unsigned i = 0; it != end; ++it, ++i)
159 vector[i] = (*it).key; 171 vector[i] = (*it).key;
160 } 172 }
161 173
162 } // namespace WTF 174 } // namespace WTF
163 175
164 using WTF::HashCountedSet; 176 using WTF::HashCountedSet;
165 177
166 #endif // WTF_HashCountedSet_h 178 #endif // WTF_HashCountedSet_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698