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

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

Issue 1968043002: Get rid of 'PassInType' in hash traits and containers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/wtf/HashTable.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed.
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 static T emptyValue() { return T(); } 95 static T emptyValue() { return T(); }
96 96
97 // Type for functions that do not take ownership, such as contains. 97 // Type for functions that do not take ownership, such as contains.
98 typedef const T& PeekInType; 98 typedef const T& PeekInType;
99 typedef T* IteratorGetType; 99 typedef T* IteratorGetType;
100 typedef const T* IteratorConstGetType; 100 typedef const T* IteratorConstGetType;
101 typedef T& IteratorReferenceType; 101 typedef T& IteratorReferenceType;
102 typedef const T& IteratorConstReferenceType; 102 typedef const T& IteratorConstReferenceType;
103 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; } 103 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; }
104 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; } 104 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; }
105 // Type for functions that take ownership, such as add. 105
106 // The store function either not be called or called once to store something
107 // passed in. The value passed to the store function will be PassInType.
108 typedef const T& PassInType;
109 template <typename IncomingValueType> 106 template <typename IncomingValueType>
110 static void store(IncomingValueType&& value, T& storage) { storage = std::fo rward<IncomingValueType>(value); } 107 static void store(IncomingValueType&& value, T& storage) { storage = std::fo rward<IncomingValueType>(value); }
111 108
112 // Type for return value of functions that do not transfer ownership, such 109 // Type for return value of functions that do not transfer ownership, such
113 // as get. 110 // as get.
114 // FIXME: We could change this type to const T& for better performance if we 111 // FIXME: We could change this type to const T& for better performance if we
115 // figured out a way to handle the return value from emptyValue, which is a 112 // figured out a way to handle the return value from emptyValue, which is a
116 // temporary. 113 // temporary.
117 typedef T PeekOutType; 114 typedef T PeekOutType;
118 static const T& peek(const T& value) { return value; } 115 static const T& peek(const T& value) { return value; }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 template <typename P> struct HashTraits<OwnPtr<P>> : SimpleClassHashTraits<OwnPt r<P>> { 154 template <typename P> struct HashTraits<OwnPtr<P>> : SimpleClassHashTraits<OwnPt r<P>> {
158 typedef std::nullptr_t EmptyValueType; 155 typedef std::nullptr_t EmptyValueType;
159 156
160 static EmptyValueType emptyValue() { return nullptr; } 157 static EmptyValueType emptyValue() { return nullptr; }
161 158
162 static const bool hasIsEmptyValueFunction = true; 159 static const bool hasIsEmptyValueFunction = true;
163 static bool isEmptyValue(const OwnPtr<P>& value) { return !value; } 160 static bool isEmptyValue(const OwnPtr<P>& value) { return !value; }
164 161
165 typedef typename OwnPtr<P>::PtrType PeekInType; 162 typedef typename OwnPtr<P>::PtrType PeekInType;
166 163
167 typedef PassOwnPtr<P> PassInType;
168 static void store(PassOwnPtr<P> value, OwnPtr<P>& storage) { storage = std:: move(value); } 164 static void store(PassOwnPtr<P> value, OwnPtr<P>& storage) { storage = std:: move(value); }
169 165
170 typedef typename OwnPtr<P>::PtrType PeekOutType; 166 typedef typename OwnPtr<P>::PtrType PeekOutType;
171 static PeekOutType peek(const OwnPtr<P>& value) { return value.get(); } 167 static PeekOutType peek(const OwnPtr<P>& value) { return value.get(); }
172 static PeekOutType peek(std::nullptr_t) { return 0; } 168 static PeekOutType peek(std::nullptr_t) { return 0; }
173 }; 169 };
174 170
175 template <typename P> struct HashTraits<RefPtr<P>> : SimpleClassHashTraits<RefPt r<P>> { 171 template <typename P> struct HashTraits<RefPtr<P>> : SimpleClassHashTraits<RefPt r<P>> {
176 typedef std::nullptr_t EmptyValueType; 172 typedef std::nullptr_t EmptyValueType;
177 static EmptyValueType emptyValue() { return nullptr; } 173 static EmptyValueType emptyValue() { return nullptr; }
178 174
179 static const bool hasIsEmptyValueFunction = true; 175 static const bool hasIsEmptyValueFunction = true;
180 static bool isEmptyValue(const RefPtr<P>& value) { return !value; } 176 static bool isEmptyValue(const RefPtr<P>& value) { return !value; }
181 177
182 typedef RefPtrValuePeeker<P> PeekInType; 178 typedef RefPtrValuePeeker<P> PeekInType;
183 typedef RefPtr<P>* IteratorGetType; 179 typedef RefPtr<P>* IteratorGetType;
184 typedef const RefPtr<P>* IteratorConstGetType; 180 typedef const RefPtr<P>* IteratorConstGetType;
185 typedef RefPtr<P>& IteratorReferenceType; 181 typedef RefPtr<P>& IteratorReferenceType;
186 typedef const RefPtr<P>& IteratorConstReferenceType; 182 typedef const RefPtr<P>& IteratorConstReferenceType;
187 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; } 183 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn *x; }
188 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; } 184 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return *x; }
189 185
190 typedef PassRefPtr<P> PassInType;
191 static void store(PassRefPtr<P> value, RefPtr<P>& storage) { storage = value ; } 186 static void store(PassRefPtr<P> value, RefPtr<P>& storage) { storage = value ; }
192 187
193 typedef P* PeekOutType; 188 typedef P* PeekOutType;
194 static PeekOutType peek(const RefPtr<P>& value) { return value.get(); } 189 static PeekOutType peek(const RefPtr<P>& value) { return value.get(); }
195 static PeekOutType peek(std::nullptr_t) { return 0; } 190 static PeekOutType peek(std::nullptr_t) { return 0; }
196 }; 191 };
197 192
198 template <typename T> 193 template <typename T>
199 struct HashTraits<std::unique_ptr<T>> : SimpleClassHashTraits<std::unique_ptr<T> > { 194 struct HashTraits<std::unique_ptr<T>> : SimpleClassHashTraits<std::unique_ptr<T> > {
200 using EmptyValueType = std::nullptr_t; 195 using EmptyValueType = std::nullptr_t;
201 static EmptyValueType emptyValue() { return nullptr; } 196 static EmptyValueType emptyValue() { return nullptr; }
202 197
203 static const bool hasIsEmptyValueFunction = true; 198 static const bool hasIsEmptyValueFunction = true;
204 static bool isEmptyValue(const std::unique_ptr<T>& value) { return !value; } 199 static bool isEmptyValue(const std::unique_ptr<T>& value) { return !value; }
205 200
206 using PeekInType = T*; 201 using PeekInType = T*;
207 202
208 using PassInType = std::unique_ptr<T>;
209 static void store(std::unique_ptr<T>&& value, std::unique_ptr<T>& storage) { storage = std::move(value); } 203 static void store(std::unique_ptr<T>&& value, std::unique_ptr<T>& storage) { storage = std::move(value); }
210 204
211 using PeekOutType = T*; 205 using PeekOutType = T*;
212 static PeekOutType peek(const std::unique_ptr<T>& value) { return value.get( ); } 206 static PeekOutType peek(const std::unique_ptr<T>& value) { return value.get( ); }
213 static PeekOutType peek(std::nullptr_t) { return nullptr; } 207 static PeekOutType peek(std::nullptr_t) { return nullptr; }
214 208
215 static void constructDeletedValue(std::unique_ptr<T>& slot, bool) 209 static void constructDeletedValue(std::unique_ptr<T>& slot, bool)
216 { 210 {
217 // Dirty trick: implant an invalid pointer to unique_ptr. Destructor isn 't called for deleted buckets, 211 // Dirty trick: implant an invalid pointer to unique_ptr. Destructor isn 't called for deleted buckets,
218 // so this is okay. 212 // so this is okay.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 struct TraceInCollectionTrait; 342 struct TraceInCollectionTrait;
349 343
350 } // namespace WTF 344 } // namespace WTF
351 345
352 using WTF::HashTraits; 346 using WTF::HashTraits;
353 using WTF::PairHashTraits; 347 using WTF::PairHashTraits;
354 using WTF::NullableHashTraits; 348 using WTF::NullableHashTraits;
355 using WTF::SimpleClassHashTraits; 349 using WTF::SimpleClassHashTraits;
356 350
357 #endif // WTF_HashTraits_h 351 #endif // WTF_HashTraits_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/HashTable.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698