| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 30 matching lines...) Expand all Loading... |
| 41 // allocation policy (P). The policy is used for allocating lists in | 41 // allocation policy (P). The policy is used for allocating lists in |
| 42 // the C free store or the zone; see zone.h. | 42 // the C free store or the zone; see zone.h. |
| 43 | 43 |
| 44 // Forward defined as | 44 // Forward defined as |
| 45 // template <typename T, class P = FreeStoreAllocationPolicy> class List; | 45 // template <typename T, class P = FreeStoreAllocationPolicy> class List; |
| 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(explicit List(const List<T, P>& other)); | |
| 52 INLINE(~List()) { DeleteData(data_); } | 51 INLINE(~List()) { DeleteData(data_); } |
| 53 | 52 |
| 54 INLINE(void* operator new(size_t size)) { return P::New(size); } | 53 INLINE(void* operator new(size_t size)) { return P::New(size); } |
| 55 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); } |
| 56 | 55 |
| 57 // Returns a reference to the element at index i. This reference is | 56 // Returns a reference to the element at index i. This reference is |
| 58 // not safe to use after operations that can change the list's | 57 // not safe to use after operations that can change the list's |
| 59 // backing store (eg, Add). | 58 // backing store (eg, Add). |
| 60 inline T& operator[](int i) const { | 59 inline T& operator[](int i) const { |
| 61 ASSERT(0 <= i && i < length_); | 60 ASSERT(0 <= i && i < length_); |
| 62 return data_[i]; | 61 return data_[i]; |
| 63 } | 62 } |
| 64 inline T& at(int i) const { return operator[](i); } | 63 inline T& at(int i) const { return operator[](i); } |
| 65 inline T& last() const { | 64 inline T& last() const { |
| 66 return at(length_ - 1); | 65 return at(length_ - 1); |
| 67 } | 66 } |
| 68 | 67 |
| 69 INLINE(bool is_empty() const) { return length_ == 0; } | 68 INLINE(bool is_empty() const) { return length_ == 0; } |
| 70 INLINE(int length() const) { return length_; } | 69 INLINE(int length() const) { return length_; } |
| 71 INLINE(int capacity() const) { return capacity_; } | 70 INLINE(int capacity() const) { return capacity_; } |
| 72 | 71 |
| 73 Vector<T> ToVector() { return Vector<T>(data_, length_); } | 72 Vector<T> ToVector() { return Vector<T>(data_, length_); } |
| 74 | 73 |
| 75 Vector<const T> ToConstVector() { return Vector<const T>(data_, length_); } | 74 Vector<const T> ToConstVector() { return Vector<const T>(data_, length_); } |
| 76 | 75 |
| 77 // Adds a copy of the given 'element' to the end of the list, | 76 // Adds a copy of the given 'element' to the end of the list, |
| 78 // expanding the list if necessary. | 77 // expanding the list if necessary. |
| 79 void Add(const T& element); | 78 void Add(const T& element); |
| 80 | 79 |
| 80 // Add all the elements from the argument list to this list. |
| 81 void AddAll(const List<T, P>& other); |
| 82 |
| 81 // Added 'count' elements with the value 'value' and returns a | 83 // Added 'count' elements with the value 'value' and returns a |
| 82 // vector that allows access to the elements. The vector is valid | 84 // vector that allows access to the elements. The vector is valid |
| 83 // until the next change is made to this list. | 85 // until the next change is made to this list. |
| 84 Vector<T> AddBlock(T value, int count); | 86 Vector<T> AddBlock(T value, int count); |
| 85 | 87 |
| 86 // Removes the i'th element without deleting it even if T is a | 88 // Removes the i'th element without deleting it even if T is a |
| 87 // pointer type; moves all elements above i "down". Returns the | 89 // pointer type; moves all elements above i "down". Returns the |
| 88 // removed element. This function's complexity is linear in the | 90 // removed element. This function's complexity is linear in the |
| 89 // size of the list. | 91 // size of the list. |
| 90 T Remove(int i); | 92 T Remove(int i); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 119 INLINE(T* NewData(int n)) { return static_cast<T*>(P::New(n * sizeof(T))); } | 121 INLINE(T* NewData(int n)) { return static_cast<T*>(P::New(n * sizeof(T))); } |
| 120 INLINE(void DeleteData(T* data)) { P::Delete(data); } | 122 INLINE(void DeleteData(T* data)) { P::Delete(data); } |
| 121 | 123 |
| 122 // Increase the capacity of a full list, and add an element. | 124 // Increase the capacity of a full list, and add an element. |
| 123 // List must be full already. | 125 // List must be full already. |
| 124 void ResizeAdd(const T& element); | 126 void ResizeAdd(const T& element); |
| 125 | 127 |
| 126 // Inlined implementation of ResizeAdd, shared by inlined and | 128 // Inlined implementation of ResizeAdd, shared by inlined and |
| 127 // non-inlined versions of ResizeAdd. | 129 // non-inlined versions of ResizeAdd. |
| 128 void ResizeAddInternal(const T& element); | 130 void ResizeAddInternal(const T& element); |
| 131 |
| 132 // Resize the list. |
| 133 void Resize(int new_capacity); |
| 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(List); |
| 129 }; | 136 }; |
| 130 | 137 |
| 131 class FrameElement; | 138 class FrameElement; |
| 132 | 139 |
| 133 // Add() is inlined, ResizeAdd() called by Add() is inlined except for | 140 // Add() is inlined, ResizeAdd() called by Add() is inlined except for |
| 134 // Lists of FrameElements, and ResizeAddInternal() is inlined in ResizeAdd(). | 141 // Lists of FrameElements, and ResizeAddInternal() is inlined in ResizeAdd(). |
| 135 template <> | 142 template <> |
| 136 void List<FrameElement, | 143 void List<FrameElement, |
| 137 FreeStoreAllocationPolicy>::ResizeAdd(const FrameElement& element); | 144 FreeStoreAllocationPolicy>::ResizeAdd(const FrameElement& element); |
| 138 | 145 |
| 139 } } // namespace v8::internal | 146 } } // namespace v8::internal |
| 140 | 147 |
| 141 #endif // V8_LIST_H_ | 148 #endif // V8_LIST_H_ |
| OLD | NEW |