Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: src/list-inl.h

Issue 6529055: [Isolates] Merge crankshaft (r5922 from bleeding_edge). (Closed)
Patch Set: Win32 port Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/list.h ('k') | src/lithium-allocator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 template<typename T, class P> 90 template<typename T, class P>
91 Vector<T> List<T, P>::AddBlock(T value, int count) { 91 Vector<T> List<T, P>::AddBlock(T value, int count) {
92 int start = length_; 92 int start = length_;
93 for (int i = 0; i < count; i++) Add(value); 93 for (int i = 0; i < count; i++) Add(value);
94 return Vector<T>(&data_[start], count); 94 return Vector<T>(&data_[start], count);
95 } 95 }
96 96
97 97
98 template<typename T, class P> 98 template<typename T, class P>
99 void List<T, P>::InsertAt(int index, const T& elm) {
100 ASSERT(index >= 0 && index <= length_);
101 Add(elm);
102 for (int i = length_ - 1; i > index; --i) {
103 data_[i] = data_[i - 1];
104 }
105 data_[index] = elm;
106 }
107
108
109 template<typename T, class P>
99 T List<T, P>::Remove(int i) { 110 T List<T, P>::Remove(int i) {
100 T element = at(i); 111 T element = at(i);
101 length_--; 112 length_--;
102 while (i < length_) { 113 while (i < length_) {
103 data_[i] = data_[i + 1]; 114 data_[i] = data_[i + 1];
104 i++; 115 i++;
105 } 116 }
106 return element; 117 return element;
107 } 118 }
108 119
109 120
110 template<typename T, class P> 121 template<typename T, class P>
122 bool List<T, P>::RemoveElement(const T& elm) {
123 for (int i = 0; i < length_; i++) {
124 if (data_[i] == elm) {
125 Remove(i);
126 return true;
127 }
128 }
129 return false;
130 }
131
132
133 template<typename T, class P>
111 void List<T, P>::Clear() { 134 void List<T, P>::Clear() {
112 DeleteData(data_); 135 DeleteData(data_);
113 Initialize(0); 136 Initialize(0);
114 } 137 }
115 138
116 139
117 template<typename T, class P> 140 template<typename T, class P>
118 void List<T, P>::Rewind(int pos) { 141 void List<T, P>::Rewind(int pos) {
119 length_ = pos; 142 length_ = pos;
120 } 143 }
121 144
122 145
123 template<typename T, class P> 146 template<typename T, class P>
124 void List<T, P>::Iterate(void (*callback)(T* x)) { 147 void List<T, P>::Iterate(void (*callback)(T* x)) {
125 for (int i = 0; i < length_; i++) callback(&data_[i]); 148 for (int i = 0; i < length_; i++) callback(&data_[i]);
126 } 149 }
127 150
128 151
129 template<typename T, class P> 152 template<typename T, class P>
130 template<class Visitor> 153 template<class Visitor>
131 void List<T, P>::Iterate(Visitor* visitor) { 154 void List<T, P>::Iterate(Visitor* visitor) {
132 for (int i = 0; i < length_; i++) visitor->Apply(&data_[i]); 155 for (int i = 0; i < length_; i++) visitor->Apply(&data_[i]);
133 } 156 }
134 157
135 158
136 template<typename T, class P> 159 template<typename T, class P>
137 bool List<T, P>::Contains(const T& elm) { 160 bool List<T, P>::Contains(const T& elm) const {
138 for (int i = 0; i < length_; i++) { 161 for (int i = 0; i < length_; i++) {
139 if (data_[i] == elm) 162 if (data_[i] == elm)
140 return true; 163 return true;
141 } 164 }
142 return false; 165 return false;
143 } 166 }
144 167
145 168
146 template<typename T, class P> 169 template<typename T, class P>
170 int List<T, P>::CountOccurrences(const T& elm, int start, int end) const {
171 int result = 0;
172 for (int i = start; i <= end; i++) {
173 if (data_[i] == elm) ++result;
174 }
175 return result;
176 }
177
178
179 template<typename T, class P>
147 void List<T, P>::Sort(int (*cmp)(const T* x, const T* y)) { 180 void List<T, P>::Sort(int (*cmp)(const T* x, const T* y)) {
148 ToVector().Sort(cmp); 181 ToVector().Sort(cmp);
149 #ifdef DEBUG 182 #ifdef DEBUG
150 for (int i = 1; i < length_; i++) 183 for (int i = 1; i < length_; i++)
151 ASSERT(cmp(&data_[i - 1], &data_[i]) <= 0); 184 ASSERT(cmp(&data_[i - 1], &data_[i]) <= 0);
152 #endif 185 #endif
153 } 186 }
154 187
155 188
156 template<typename T, class P> 189 template<typename T, class P>
157 void List<T, P>::Sort() { 190 void List<T, P>::Sort() {
158 Sort(PointerValueCompare<T>); 191 Sort(PointerValueCompare<T>);
159 } 192 }
160 193
161 194
162 template<typename T, class P> 195 template<typename T, class P>
163 void List<T, P>::Initialize(int capacity) { 196 void List<T, P>::Initialize(int capacity) {
164 ASSERT(capacity >= 0); 197 ASSERT(capacity >= 0);
165 data_ = (capacity > 0) ? NewData(capacity) : NULL; 198 data_ = (capacity > 0) ? NewData(capacity) : NULL;
166 capacity_ = capacity; 199 capacity_ = capacity;
167 length_ = 0; 200 length_ = 0;
168 } 201 }
169 202
170 203
171 } } // namespace v8::internal 204 } } // namespace v8::internal
172 205
173 #endif // V8_LIST_INL_H_ 206 #endif // V8_LIST_INL_H_
OLDNEW
« no previous file with comments | « src/list.h ('k') | src/lithium-allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698