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

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

Issue 2274403002: Replace two ASSERT()s for HashMap iterators with DCHECK_NE()s. (Closed)
Patch Set: Created 4 years, 3 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/core/html/forms/RadioButtonGroupScope.cpp ('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 * Copyright (C) 2008 David Levin <levin@chromium.org> 3 * Copyright (C) 2008 David Levin <levin@chromium.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 197 }
198 bool operator==(const iterator& other) const 198 bool operator==(const iterator& other) const
199 { 199 {
200 return *this == static_cast<const_iterator>(other); 200 return *this == static_cast<const_iterator>(other);
201 } 201 }
202 bool operator!=(const iterator& other) const 202 bool operator!=(const iterator& other) const
203 { 203 {
204 return *this != static_cast<const_iterator>(other); 204 return *this != static_cast<const_iterator>(other);
205 } 205 }
206 206
207 std::ostream& printTo(std::ostream& stream) const
208 {
209 if (m_position == m_endPosition)
210 return stream << "iterator representing <end>";
211 // TODO(tkent): Change |m_position| to |*m_position| to show the
212 // pointed object. It requires a lot of new stream printer functions.
213 return stream << "iterator pointing to " << m_position;
214 }
215
207 private: 216 private:
208 PointerType m_position; 217 PointerType m_position;
209 PointerType m_endPosition; 218 PointerType m_endPosition;
210 #if ENABLE(ASSERT) 219 #if ENABLE(ASSERT)
211 const HashTableType* m_container; 220 const HashTableType* m_container;
212 int64_t m_containerModifications; 221 int64_t m_containerModifications;
213 #endif 222 #endif
214 }; 223 };
215 224
225 template <typename Key, typename Value, typename Extractor, typename Hash, typen ame Traits, typename KeyTraits, typename Allocator>
226 std::ostream& operator<<(std::ostream& stream, const HashTableConstIterator<Key, Value, Extractor, Hash, Traits, KeyTraits, Allocator>& iterator)
227 {
228 return iterator.printTo(stream);
229 }
230
216 template <typename Key, typename Value, typename Extractor, typename HashFunctio ns, typename Traits, typename KeyTraits, typename Allocator> 231 template <typename Key, typename Value, typename Extractor, typename HashFunctio ns, typename Traits, typename KeyTraits, typename Allocator>
217 class HashTableIterator final { 232 class HashTableIterator final {
218 DISALLOW_NEW(); 233 DISALLOW_NEW();
219 private: 234 private:
220 typedef HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, A llocator> HashTableType; 235 typedef HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, A llocator> HashTableType;
221 typedef HashTableIterator<Key, Value, Extractor, HashFunctions, Traits, KeyT raits, Allocator> iterator; 236 typedef HashTableIterator<Key, Value, Extractor, HashFunctions, Traits, KeyT raits, Allocator> iterator;
222 typedef HashTableConstIterator<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator> const_iterator; 237 typedef HashTableConstIterator<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator> const_iterator;
223 typedef Value ValueType; 238 typedef Value ValueType;
224 typedef typename Traits::IteratorGetType GetType; 239 typedef typename Traits::IteratorGetType GetType;
225 typedef ValueType* PointerType; 240 typedef ValueType* PointerType;
(...skipping 16 matching lines...) Expand all
242 257
243 // postfix ++ intentionally omitted 258 // postfix ++ intentionally omitted
244 259
245 // Comparison. 260 // Comparison.
246 bool operator==(const iterator& other) const { return m_iterator == other.m_ iterator; } 261 bool operator==(const iterator& other) const { return m_iterator == other.m_ iterator; }
247 bool operator!=(const iterator& other) const { return m_iterator != other.m_ iterator; } 262 bool operator!=(const iterator& other) const { return m_iterator != other.m_ iterator; }
248 bool operator==(const const_iterator& other) const { return m_iterator == ot her; } 263 bool operator==(const const_iterator& other) const { return m_iterator == ot her; }
249 bool operator!=(const const_iterator& other) const { return m_iterator != ot her; } 264 bool operator!=(const const_iterator& other) const { return m_iterator != ot her; }
250 265
251 operator const_iterator() const { return m_iterator; } 266 operator const_iterator() const { return m_iterator; }
267 std::ostream& printTo(std::ostream& stream) const { return m_iterator.printT o(stream); }
252 268
253 private: 269 private:
254 const_iterator m_iterator; 270 const_iterator m_iterator;
255 }; 271 };
256 272
273 template <typename Key, typename Value, typename Extractor, typename Hash, typen ame Traits, typename KeyTraits, typename Allocator>
274 std::ostream& operator<<(std::ostream& stream, const HashTableIterator<Key, Valu e, Extractor, Hash, Traits, KeyTraits, Allocator>& iterator)
275 {
276 return iterator.printTo(stream);
277 }
278
257 using std::swap; 279 using std::swap;
258 280
259 template <typename T, typename Allocator, bool enterGCForbiddenScope> struct Mov er { 281 template <typename T, typename Allocator, bool enterGCForbiddenScope> struct Mov er {
260 STATIC_ONLY(Mover); 282 STATIC_ONLY(Mover);
261 static void move(T&& from, T& to) 283 static void move(T&& from, T& to)
262 { 284 {
263 to.~T(); 285 to.~T();
264 new (NotNull, &to) T(std::move(from)); 286 new (NotNull, &to) T(std::move(from));
265 } 287 }
266 }; 288 };
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 GetType get() const { return const_cast<GetType>(SourceGetType(m_impl.get()) ); } 1475 GetType get() const { return const_cast<GetType>(SourceGetType(m_impl.get()) ); }
1454 typename Traits::IteratorConstReferenceType operator*() const { return Trait s::getToReferenceConstConversion(get()); } 1476 typename Traits::IteratorConstReferenceType operator*() const { return Trait s::getToReferenceConstConversion(get()); }
1455 GetType operator->() const { return get(); } 1477 GetType operator->() const { return get(); }
1456 1478
1457 HashTableConstIteratorAdapter& operator++() { ++m_impl; return *this; } 1479 HashTableConstIteratorAdapter& operator++() { ++m_impl; return *this; }
1458 // postfix ++ intentionally omitted 1480 // postfix ++ intentionally omitted
1459 1481
1460 typename HashTableType::const_iterator m_impl; 1482 typename HashTableType::const_iterator m_impl;
1461 }; 1483 };
1462 1484
1485 template <typename HashTable, typename Traits>
1486 std::ostream& operator<<(std::ostream& stream, const HashTableConstIteratorAdapt er<HashTable, Traits>& iterator)
1487 {
1488 return stream << iterator.m_impl;
1489 }
1490
1463 template <typename HashTableType, typename Traits> struct HashTableIteratorAdapt er { 1491 template <typename HashTableType, typename Traits> struct HashTableIteratorAdapt er {
1464 STACK_ALLOCATED(); 1492 STACK_ALLOCATED();
1465 typedef typename Traits::IteratorGetType GetType; 1493 typedef typename Traits::IteratorGetType GetType;
1466 typedef typename HashTableType::ValueTraits::IteratorGetType SourceGetType; 1494 typedef typename HashTableType::ValueTraits::IteratorGetType SourceGetType;
1467 1495
1468 HashTableIteratorAdapter() {} 1496 HashTableIteratorAdapter() {}
1469 HashTableIteratorAdapter(const typename HashTableType::iterator& impl) : m_i mpl(impl) {} 1497 HashTableIteratorAdapter(const typename HashTableType::iterator& impl) : m_i mpl(impl) {}
1470 1498
1471 GetType get() const { return const_cast<GetType>(SourceGetType(m_impl.get()) ); } 1499 GetType get() const { return const_cast<GetType>(SourceGetType(m_impl.get()) ); }
1472 typename Traits::IteratorReferenceType operator*() const { return Traits::ge tToReferenceConversion(get()); } 1500 typename Traits::IteratorReferenceType operator*() const { return Traits::ge tToReferenceConversion(get()); }
1473 GetType operator->() const { return get(); } 1501 GetType operator->() const { return get(); }
1474 1502
1475 HashTableIteratorAdapter& operator++() { ++m_impl; return *this; } 1503 HashTableIteratorAdapter& operator++() { ++m_impl; return *this; }
1476 // postfix ++ intentionally omitted 1504 // postfix ++ intentionally omitted
1477 1505
1478 operator HashTableConstIteratorAdapter<HashTableType, Traits>() 1506 operator HashTableConstIteratorAdapter<HashTableType, Traits>()
1479 { 1507 {
1480 typename HashTableType::const_iterator i = m_impl; 1508 typename HashTableType::const_iterator i = m_impl;
1481 return i; 1509 return i;
1482 } 1510 }
1483 1511
1484 typename HashTableType::iterator m_impl; 1512 typename HashTableType::iterator m_impl;
1485 }; 1513 };
1486 1514
1515 template <typename HashTable, typename Traits>
1516 std::ostream& operator<<(std::ostream& stream, const HashTableIteratorAdapter<Ha shTable, Traits>& iterator)
1517 {
1518 return stream << iterator.m_impl;
1519 }
1520
1487 template <typename T, typename U> 1521 template <typename T, typename U>
1488 inline bool operator==(const HashTableConstIteratorAdapter<T, U>& a, const HashT ableConstIteratorAdapter<T, U>& b) 1522 inline bool operator==(const HashTableConstIteratorAdapter<T, U>& a, const HashT ableConstIteratorAdapter<T, U>& b)
1489 { 1523 {
1490 return a.m_impl == b.m_impl; 1524 return a.m_impl == b.m_impl;
1491 } 1525 }
1492 1526
1493 template <typename T, typename U> 1527 template <typename T, typename U>
1494 inline bool operator!=(const HashTableConstIteratorAdapter<T, U>& a, const HashT ableConstIteratorAdapter<T, U>& b) 1528 inline bool operator!=(const HashTableConstIteratorAdapter<T, U>& a, const HashT ableConstIteratorAdapter<T, U>& b)
1495 { 1529 {
1496 return a.m_impl != b.m_impl; 1530 return a.m_impl != b.m_impl;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 CollectionIterator end(toBeRemoved.end()); 1576 CollectionIterator end(toBeRemoved.end());
1543 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) 1577 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it)
1544 collection.remove(*it); 1578 collection.remove(*it);
1545 } 1579 }
1546 1580
1547 } // namespace WTF 1581 } // namespace WTF
1548 1582
1549 #include "wtf/HashIterators.h" 1583 #include "wtf/HashIterators.h"
1550 1584
1551 #endif // WTF_HashTable_h 1585 #endif // WTF_HashTable_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/forms/RadioButtonGroupScope.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698