Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Google Inc. All rights reserved. | 3 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 | 127 |
| 128 template <typename U> | 128 template <typename U> |
| 129 void append(U&&); | 129 void append(U&&); |
| 130 template <typename U> | 130 template <typename U> |
| 131 void prepend(U&&); | 131 void prepend(U&&); |
| 132 void removeFirst(); | 132 void removeFirst(); |
| 133 void removeLast(); | 133 void removeLast(); |
| 134 void remove(iterator&); | 134 void remove(iterator&); |
| 135 void remove(const_iterator&); | 135 void remove(const_iterator&); |
| 136 | 136 |
| 137 // STL compatibility. | |
| 138 template <typename U> | |
| 139 void push_back(U&& u) { | |
| 140 append(std::forward<U>(u)); | |
| 141 } | |
| 142 template <typename U> | |
| 143 void push_front(U&& u) { | |
| 144 prepend(std::forward<U>(u)); | |
| 145 } | |
| 146 void pop_back() { removeLast(); } | |
| 147 void pop_front() { removeFirst(); } | |
| 148 bool empty() const { return isEmpty(); } | |
| 149 T& front() { return first(); } | |
| 150 const T& front() const { return first(); } | |
| 151 T& back() { return last(); } | |
| 152 const T& back() const { return last(); } | |
| 153 template <typename... Args> | |
| 154 void emplace_back(Args&&...); | |
| 155 template <typename... Args> | |
| 156 void emplace_front(Args&&...); | |
| 157 | |
| 137 void clear(); | 158 void clear(); |
| 138 | 159 |
| 139 template <typename VisitorDispatcher> | 160 template <typename VisitorDispatcher> |
| 140 void trace(VisitorDispatcher); | 161 void trace(VisitorDispatcher); |
| 141 | 162 |
| 142 static_assert(!std::is_polymorphic<T>::value || | 163 static_assert(!std::is_polymorphic<T>::value || |
| 143 !VectorTraits<T>::canInitializeWithMemset, | 164 !VectorTraits<T>::canInitializeWithMemset, |
| 144 "Cannot initialize with memset if there is a vtable"); | 165 "Cannot initialize with memset if there is a vtable"); |
| 145 static_assert(Allocator::isGarbageCollected || | 166 static_assert(Allocator::isGarbageCollected || |
| 146 !AllowsOnlyPlacementNew<T>::value || | 167 !AllowsOnlyPlacementNew<T>::value || |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 inline void Deque<T, inlineCapacity, Allocator>::prepend(U&& value) { | 518 inline void Deque<T, inlineCapacity, Allocator>::prepend(U&& value) { |
| 498 expandCapacityIfNeeded(); | 519 expandCapacityIfNeeded(); |
| 499 if (!m_start) | 520 if (!m_start) |
| 500 m_start = m_buffer.capacity() - 1; | 521 m_start = m_buffer.capacity() - 1; |
| 501 else | 522 else |
| 502 --m_start; | 523 --m_start; |
| 503 new (NotNull, &m_buffer.buffer()[m_start]) T(std::forward<U>(value)); | 524 new (NotNull, &m_buffer.buffer()[m_start]) T(std::forward<U>(value)); |
| 504 } | 525 } |
| 505 | 526 |
| 506 template <typename T, size_t inlineCapacity, typename Allocator> | 527 template <typename T, size_t inlineCapacity, typename Allocator> |
| 528 template <typename... Args> | |
| 529 inline void Deque<T, inlineCapacity, Allocator>::emplace_back(Args&&... args) { | |
| 530 expandCapacityIfNeeded(); | |
| 531 new (NotNull, &m_buffer.buffer()[m_end]) T(std::forward<Args>(args)...); | |
| 532 if (m_end == m_buffer.capacity() - 1) | |
|
Sami
2017/01/11 13:49:11
Looks like this already exists with the current co
alex clarke (OOO till 29th)
2017/01/11 14:04:26
Done.
| |
| 533 m_end = 0; | |
| 534 else | |
| 535 ++m_end; | |
| 536 } | |
| 537 | |
| 538 template <typename T, size_t inlineCapacity, typename Allocator> | |
| 539 template <typename... Args> | |
| 540 inline void Deque<T, inlineCapacity, Allocator>::emplace_front(Args&&... args) { | |
| 541 expandCapacityIfNeeded(); | |
| 542 if (!m_start) | |
| 543 m_start = m_buffer.capacity() - 1; | |
| 544 else | |
| 545 --m_start; | |
| 546 new (NotNull, &m_buffer.buffer()[m_start]) T(std::forward<Args>(args)...); | |
| 547 } | |
| 548 | |
| 549 template <typename T, size_t inlineCapacity, typename Allocator> | |
| 507 inline void Deque<T, inlineCapacity, Allocator>::removeFirst() { | 550 inline void Deque<T, inlineCapacity, Allocator>::removeFirst() { |
| 508 DCHECK(!isEmpty()); | 551 DCHECK(!isEmpty()); |
| 509 TypeOperations::destruct(&m_buffer.buffer()[m_start], | 552 TypeOperations::destruct(&m_buffer.buffer()[m_start], |
| 510 &m_buffer.buffer()[m_start + 1]); | 553 &m_buffer.buffer()[m_start + 1]); |
| 511 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_start], | 554 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_start], |
| 512 &m_buffer.buffer()[m_start + 1]); | 555 &m_buffer.buffer()[m_start + 1]); |
| 513 if (m_start == m_buffer.capacity() - 1) | 556 if (m_start == m_buffer.capacity() - 1) |
| 514 m_start = 0; | 557 m_start = 0; |
| 515 else | 558 else |
| 516 ++m_start; | 559 ++m_start; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 inline void swap(Deque<T, inlineCapacity, Allocator>& a, | 709 inline void swap(Deque<T, inlineCapacity, Allocator>& a, |
| 667 Deque<T, inlineCapacity, Allocator>& b) { | 710 Deque<T, inlineCapacity, Allocator>& b) { |
| 668 a.swap(b); | 711 a.swap(b); |
| 669 } | 712 } |
| 670 | 713 |
| 671 } // namespace WTF | 714 } // namespace WTF |
| 672 | 715 |
| 673 using WTF::Deque; | 716 using WTF::Deque; |
| 674 | 717 |
| 675 #endif // WTF_Deque_h | 718 #endif // WTF_Deque_h |
| OLD | NEW |