| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 size_t right = m_buffer.capacity() - m_start; | 120 size_t right = m_buffer.capacity() - m_start; |
| 121 return i < right ? m_buffer.buffer()[m_start + i] | 121 return i < right ? m_buffer.buffer()[m_start + i] |
| 122 : m_buffer.buffer()[i - right]; | 122 : m_buffer.buffer()[i - right]; |
| 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 prepend(U&&); | 129 void prepend(U&&); |
| 130 void remove(iterator&); | 130 void erase(iterator&); |
| 131 void remove(const_iterator&); | 131 void erase(const_iterator&); |
| 132 | 132 |
| 133 // STL compatibility. | 133 // STL compatibility. |
| 134 template <typename U> | 134 template <typename U> |
| 135 void push_back(U&&); | 135 void push_back(U&&); |
| 136 template <typename U> | 136 template <typename U> |
| 137 void push_front(U&& u) { | 137 void push_front(U&& u) { |
| 138 prepend(std::forward<U>(u)); | 138 prepend(std::forward<U>(u)); |
| 139 } | 139 } |
| 140 void pop_back(); | 140 void pop_back(); |
| 141 void pop_front(); | 141 void pop_front(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 public: | 176 public: |
| 177 BackingBuffer() : Base() {} | 177 BackingBuffer() : Base() {} |
| 178 explicit BackingBuffer(size_t capacity) : Base(capacity) {} | 178 explicit BackingBuffer(size_t capacity) : Base(capacity) {} |
| 179 | 179 |
| 180 void setSize(size_t size) { m_size = size; } | 180 void setSize(size_t size) { m_size = size; } |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 typedef VectorTypeOperations<T> TypeOperations; | 183 typedef VectorTypeOperations<T> TypeOperations; |
| 184 typedef DequeIteratorBase<T, inlineCapacity, Allocator> IteratorBase; | 184 typedef DequeIteratorBase<T, inlineCapacity, Allocator> IteratorBase; |
| 185 | 185 |
| 186 void remove(size_t position); | 186 void erase(size_t position); |
| 187 void destroyAll(); | 187 void destroyAll(); |
| 188 void expandCapacityIfNeeded(); | 188 void expandCapacityIfNeeded(); |
| 189 void expandCapacity(); | 189 void expandCapacity(); |
| 190 | 190 |
| 191 BackingBuffer m_buffer; | 191 BackingBuffer m_buffer; |
| 192 unsigned m_start; | 192 unsigned m_start; |
| 193 unsigned m_end; | 193 unsigned m_end; |
| 194 }; | 194 }; |
| 195 | 195 |
| 196 template <typename T, size_t inlineCapacity, typename Allocator> | 196 template <typename T, size_t inlineCapacity, typename Allocator> |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 m_end = m_buffer.capacity() - 1; | 558 m_end = m_buffer.capacity() - 1; |
| 559 else | 559 else |
| 560 --m_end; | 560 --m_end; |
| 561 TypeOperations::destruct(&m_buffer.buffer()[m_end], | 561 TypeOperations::destruct(&m_buffer.buffer()[m_end], |
| 562 &m_buffer.buffer()[m_end + 1]); | 562 &m_buffer.buffer()[m_end + 1]); |
| 563 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_end], | 563 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_end], |
| 564 &m_buffer.buffer()[m_end + 1]); | 564 &m_buffer.buffer()[m_end + 1]); |
| 565 } | 565 } |
| 566 | 566 |
| 567 template <typename T, size_t inlineCapacity, typename Allocator> | 567 template <typename T, size_t inlineCapacity, typename Allocator> |
| 568 inline void Deque<T, inlineCapacity, Allocator>::remove(iterator& it) { | 568 inline void Deque<T, inlineCapacity, Allocator>::erase(iterator& it) { |
| 569 remove(it.m_index); | 569 erase(it.m_index); |
| 570 } | 570 } |
| 571 | 571 |
| 572 template <typename T, size_t inlineCapacity, typename Allocator> | 572 template <typename T, size_t inlineCapacity, typename Allocator> |
| 573 inline void Deque<T, inlineCapacity, Allocator>::remove(const_iterator& it) { | 573 inline void Deque<T, inlineCapacity, Allocator>::erase(const_iterator& it) { |
| 574 remove(it.m_index); | 574 erase(it.m_index); |
| 575 } | 575 } |
| 576 | 576 |
| 577 template <typename T, size_t inlineCapacity, typename Allocator> | 577 template <typename T, size_t inlineCapacity, typename Allocator> |
| 578 inline void Deque<T, inlineCapacity, Allocator>::remove(size_t position) { | 578 inline void Deque<T, inlineCapacity, Allocator>::erase(size_t position) { |
| 579 if (position == m_end) | 579 if (position == m_end) |
| 580 return; | 580 return; |
| 581 | 581 |
| 582 T* buffer = m_buffer.buffer(); | 582 T* buffer = m_buffer.buffer(); |
| 583 TypeOperations::destruct(&buffer[position], &buffer[position + 1]); | 583 TypeOperations::destruct(&buffer[position], &buffer[position + 1]); |
| 584 | 584 |
| 585 // Find which segment of the circular buffer contained the remove element, | 585 // Find which segment of the circular buffer contained the remove element, |
| 586 // and only move elements in that part. | 586 // and only move elements in that part. |
| 587 if (position >= m_start) { | 587 if (position >= m_start) { |
| 588 TypeOperations::moveOverlapping(buffer + m_start, buffer + position, | 588 TypeOperations::moveOverlapping(buffer + m_start, buffer + position, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 inline void swap(Deque<T, inlineCapacity, Allocator>& a, | 701 inline void swap(Deque<T, inlineCapacity, Allocator>& a, |
| 702 Deque<T, inlineCapacity, Allocator>& b) { | 702 Deque<T, inlineCapacity, Allocator>& b) { |
| 703 a.swap(b); | 703 a.swap(b); |
| 704 } | 704 } |
| 705 | 705 |
| 706 } // namespace WTF | 706 } // namespace WTF |
| 707 | 707 |
| 708 using WTF::Deque; | 708 using WTF::Deque; |
| 709 | 709 |
| 710 #endif // WTF_Deque_h | 710 #endif // WTF_Deque_h |
| OLD | NEW |