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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 123 } |
124 | 124 |
125 T& operator[](size_t i) { return at(i); } | 125 T& operator[](size_t i) { return at(i); } |
126 const T& operator[](size_t i) const { return at(i); } | 126 const T& operator[](size_t i) const { return at(i); } |
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(); | |
134 void remove(iterator&); | 133 void remove(iterator&); |
135 void remove(const_iterator&); | 134 void remove(const_iterator&); |
136 | 135 |
137 // STL compatibility. | 136 // STL compatibility. |
138 template <typename U> | 137 template <typename U> |
139 void push_back(U&& u) { | 138 void push_back(U&& u) { |
140 append(std::forward<U>(u)); | 139 append(std::forward<U>(u)); |
141 } | 140 } |
142 template <typename U> | 141 template <typename U> |
143 void push_front(U&& u) { | 142 void push_front(U&& u) { |
144 prepend(std::forward<U>(u)); | 143 prepend(std::forward<U>(u)); |
145 } | 144 } |
146 void pop_back() { removeLast(); } | 145 void pop_back(); |
147 void pop_front() { removeFirst(); } | 146 void pop_front() { removeFirst(); } |
148 bool empty() const { return isEmpty(); } | 147 bool empty() const { return isEmpty(); } |
149 T& front() { return first(); } | 148 T& front() { return first(); } |
150 const T& front() const { return first(); } | 149 const T& front() const { return first(); } |
151 T& back() { return last(); } | 150 T& back() { return last(); } |
152 const T& back() const { return last(); } | 151 const T& back() const { return last(); } |
153 template <typename... Args> | 152 template <typename... Args> |
154 void emplace_back(Args&&...); | 153 void emplace_back(Args&&...); |
155 template <typename... Args> | 154 template <typename... Args> |
156 void emplace_front(Args&&...); | 155 void emplace_front(Args&&...); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 template <typename T, size_t inlineCapacity, typename Allocator> | 490 template <typename T, size_t inlineCapacity, typename Allocator> |
492 inline T Deque<T, inlineCapacity, Allocator>::takeFirst() { | 491 inline T Deque<T, inlineCapacity, Allocator>::takeFirst() { |
493 T oldFirst = std::move(first()); | 492 T oldFirst = std::move(first()); |
494 removeFirst(); | 493 removeFirst(); |
495 return oldFirst; | 494 return oldFirst; |
496 } | 495 } |
497 | 496 |
498 template <typename T, size_t inlineCapacity, typename Allocator> | 497 template <typename T, size_t inlineCapacity, typename Allocator> |
499 inline T Deque<T, inlineCapacity, Allocator>::takeLast() { | 498 inline T Deque<T, inlineCapacity, Allocator>::takeLast() { |
500 T oldLast = std::move(last()); | 499 T oldLast = std::move(last()); |
501 removeLast(); | 500 pop_back(); |
502 return oldLast; | 501 return oldLast; |
503 } | 502 } |
504 | 503 |
505 template <typename T, size_t inlineCapacity, typename Allocator> | 504 template <typename T, size_t inlineCapacity, typename Allocator> |
506 template <typename U> | 505 template <typename U> |
507 inline void Deque<T, inlineCapacity, Allocator>::append(U&& value) { | 506 inline void Deque<T, inlineCapacity, Allocator>::append(U&& value) { |
508 expandCapacityIfNeeded(); | 507 expandCapacityIfNeeded(); |
509 T* newElement = &m_buffer.buffer()[m_end]; | 508 T* newElement = &m_buffer.buffer()[m_end]; |
510 if (m_end == m_buffer.capacity() - 1) | 509 if (m_end == m_buffer.capacity() - 1) |
511 m_end = 0; | 510 m_end = 0; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 &m_buffer.buffer()[m_start + 1]); | 554 &m_buffer.buffer()[m_start + 1]); |
556 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_start], | 555 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_start], |
557 &m_buffer.buffer()[m_start + 1]); | 556 &m_buffer.buffer()[m_start + 1]); |
558 if (m_start == m_buffer.capacity() - 1) | 557 if (m_start == m_buffer.capacity() - 1) |
559 m_start = 0; | 558 m_start = 0; |
560 else | 559 else |
561 ++m_start; | 560 ++m_start; |
562 } | 561 } |
563 | 562 |
564 template <typename T, size_t inlineCapacity, typename Allocator> | 563 template <typename T, size_t inlineCapacity, typename Allocator> |
565 inline void Deque<T, inlineCapacity, Allocator>::removeLast() { | 564 inline void Deque<T, inlineCapacity, Allocator>::pop_back() { |
566 DCHECK(!isEmpty()); | 565 DCHECK(!isEmpty()); |
567 if (!m_end) | 566 if (!m_end) |
568 m_end = m_buffer.capacity() - 1; | 567 m_end = m_buffer.capacity() - 1; |
569 else | 568 else |
570 --m_end; | 569 --m_end; |
571 TypeOperations::destruct(&m_buffer.buffer()[m_end], | 570 TypeOperations::destruct(&m_buffer.buffer()[m_end], |
572 &m_buffer.buffer()[m_end + 1]); | 571 &m_buffer.buffer()[m_end + 1]); |
573 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_end], | 572 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_end], |
574 &m_buffer.buffer()[m_end + 1]); | 573 &m_buffer.buffer()[m_end + 1]); |
575 } | 574 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 inline void swap(Deque<T, inlineCapacity, Allocator>& a, | 710 inline void swap(Deque<T, inlineCapacity, Allocator>& a, |
712 Deque<T, inlineCapacity, Allocator>& b) { | 711 Deque<T, inlineCapacity, Allocator>& b) { |
713 a.swap(b); | 712 a.swap(b); |
714 } | 713 } |
715 | 714 |
716 } // namespace WTF | 715 } // namespace WTF |
717 | 716 |
718 using WTF::Deque; | 717 using WTF::Deque; |
719 | 718 |
720 #endif // WTF_Deque_h | 719 #endif // WTF_Deque_h |
OLD | NEW |