src/share/vm/utilities/growableArray.hpp

changeset 3651
ee138854b3a6
parent 3138
f6f3bb0ee072
child 3900
d2a62e0f25eb
equal deleted inserted replaced
3636:fde683df4c27 3651:ee138854b3a6
1 /* 1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
196 int idx = _len++; 196 int idx = _len++;
197 _data[idx] = elem; 197 _data[idx] = elem;
198 return idx; 198 return idx;
199 } 199 }
200 200
201 void append_if_missing(const E& elem) { 201 bool append_if_missing(const E& elem) {
202 if (!contains(elem)) append(elem); 202 // Returns TRUE if elem is added.
203 bool missed = !contains(elem);
204 if (missed) append(elem);
205 return missed;
203 } 206 }
204 207
205 E at(int i) const { 208 E at(int i) const {
206 assert(0 <= i && i < _len, "illegal index"); 209 assert(0 <= i && i < _len, "illegal index");
207 return _data[i]; 210 return _data[i];
290 } 293 }
291 } 294 }
292 ShouldNotReachHere(); 295 ShouldNotReachHere();
293 } 296 }
294 297
298 // The order is preserved.
295 void remove_at(int index) { 299 void remove_at(int index) {
296 assert(0 <= index && index < _len, "illegal index"); 300 assert(0 <= index && index < _len, "illegal index");
297 for (int j = index + 1; j < _len; j++) _data[j-1] = _data[j]; 301 for (int j = index + 1; j < _len; j++) _data[j-1] = _data[j];
298 _len--; 302 _len--;
303 }
304
305 // The order is changed.
306 void delete_at(int index) {
307 assert(0 <= index && index < _len, "illegal index");
308 if (index < --_len) {
309 // Replace removed element with last one.
310 _data[index] = _data[_len];
311 }
299 } 312 }
300 313
301 // inserts the given element before the element at index i 314 // inserts the given element before the element at index i
302 void insert_before(const int idx, const E& elem) { 315 void insert_before(const int idx, const E& elem) {
303 check_nesting(); 316 check_nesting();

mercurial