| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 template <typename T, class P> | 46 template <typename T, class P> |
| 47 class List { | 47 class List { |
| 48 public: | 48 public: |
| 49 | 49 |
| 50 INLINE(explicit List(int capacity)) { Initialize(capacity); } | 50 INLINE(explicit List(int capacity)) { Initialize(capacity); } |
| 51 INLINE(~List()) { DeleteData(data_); } | 51 INLINE(~List()) { DeleteData(data_); } |
| 52 | 52 |
| 53 INLINE(void* operator new(size_t size)) { return P::New(size); } | 53 INLINE(void* operator new(size_t size)) { return P::New(size); } |
| 54 INLINE(void operator delete(void* p, size_t)) { return P::Delete(p); } | 54 INLINE(void operator delete(void* p, size_t)) { return P::Delete(p); } |
| 55 | 55 |
| 56 // Returns a reference to the element at index i. This reference is |
| 57 // not safe to use after operations that can change the list's |
| 58 // backing store (eg, Add). |
| 56 inline T& operator[](int i) const { | 59 inline T& operator[](int i) const { |
| 57 ASSERT(0 <= i && i < length_); | 60 ASSERT(0 <= i && i < length_); |
| 58 return data_[i]; | 61 return data_[i]; |
| 59 } | 62 } |
| 60 inline T& at(int i) const { return operator[](i); } | 63 inline T& at(int i) const { return operator[](i); } |
| 61 inline T& last() const { | 64 inline T& last() const { |
| 62 ASSERT(!is_empty()); | |
| 63 return at(length_ - 1); | 65 return at(length_ - 1); |
| 64 } | 66 } |
| 65 | 67 |
| 66 INLINE(bool is_empty() const) { return length_ == 0; } | 68 INLINE(bool is_empty() const) { return length_ == 0; } |
| 67 INLINE(int length() const) { return length_; } | 69 INLINE(int length() const) { return length_; } |
| 68 | 70 |
| 69 Vector<T> ToVector() { return Vector<T>(data_, length_); } | 71 Vector<T> ToVector() { return Vector<T>(data_, length_); } |
| 70 | 72 |
| 71 Vector<const T> ToConstVector() { return Vector<const T>(data_, length_); } | 73 Vector<const T> ToConstVector() { return Vector<const T>(data_, length_); } |
| 72 | 74 |
| 73 // Adds a copy of the given 'element' to the end of the list, | 75 // Adds a copy of the given 'element' to the end of the list, |
| 74 // expanding the list if necessary. | 76 // expanding the list if necessary. |
| 75 T& Add(const T& element); | 77 void Add(const T& element); |
| 76 | 78 |
| 77 // Added 'count' elements with the value 'value' and returns a | 79 // Added 'count' elements with the value 'value' and returns a |
| 78 // vector that allows access to the elements. The vector is valid | 80 // vector that allows access to the elements. The vector is valid |
| 79 // until the next change is made to this list. | 81 // until the next change is made to this list. |
| 80 Vector<T> AddBlock(const T& value, int count); | 82 Vector<T> AddBlock(T value, int count); |
| 81 | |
| 82 // Inserts a copy of the given element at index i in the list. All | |
| 83 // elements formerly at or above i are moved up and the length of | |
| 84 // the list increases by one. This function's complexity is linear | |
| 85 // in the size of the list. | |
| 86 T& Insert(int i, const T& element); | |
| 87 | 83 |
| 88 // Removes the i'th element without deleting it even if T is a | 84 // Removes the i'th element without deleting it even if T is a |
| 89 // pointer type; moves all elements above i "down". Returns the | 85 // pointer type; moves all elements above i "down". Returns the |
| 90 // removed element. This function's complexity is linear in the | 86 // removed element. This function's complexity is linear in the |
| 91 // size of the list. | 87 // size of the list. |
| 92 T Remove(int i); | 88 T Remove(int i); |
| 93 | 89 |
| 94 // Removes the last element without deleting it even if T is a | 90 // Removes the last element without deleting it even if T is a |
| 95 // pointer type. Returns the removed element. | 91 // pointer type. Returns the removed element. |
| 96 INLINE(T RemoveLast()) { return Remove(length_ - 1); } | 92 INLINE(T RemoveLast()) { return Remove(length_ - 1); } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 121 INLINE(T* NewData(int n)) { return static_cast<T*>(P::New(n * sizeof(T))); } | 117 INLINE(T* NewData(int n)) { return static_cast<T*>(P::New(n * sizeof(T))); } |
| 122 INLINE(void DeleteData(T* data)) { P::Delete(data); } | 118 INLINE(void DeleteData(T* data)) { P::Delete(data); } |
| 123 | 119 |
| 124 DISALLOW_COPY_AND_ASSIGN(List); | 120 DISALLOW_COPY_AND_ASSIGN(List); |
| 125 }; | 121 }; |
| 126 | 122 |
| 127 | 123 |
| 128 } } // namespace v8::internal | 124 } } // namespace v8::internal |
| 129 | 125 |
| 130 #endif // V8_LIST_H_ | 126 #endif // V8_LIST_H_ |
| OLD | NEW |