src/share/vm/utilities/growableArray.hpp

Print this page
rev 4803 : imported patch thomas-comments-2


 177   }
 178 
 179   GrowableArray(Arena* arena, int initial_size, int initial_len, const E& filler) : GenericGrowableArray(arena, initial_size, initial_len) {
 180     _data = (E*)raw_allocate(sizeof(E));
 181     int i = 0;
 182     for (; i < _len; i++) ::new ((void*)&_data[i]) E(filler);
 183     for (; i < _max; i++) ::new ((void*)&_data[i]) E();
 184   }
 185 
 186   GrowableArray() : GenericGrowableArray(2, 0, false) {
 187     _data = (E*)raw_allocate(sizeof(E));
 188     ::new ((void*)&_data[0]) E();
 189     ::new ((void*)&_data[1]) E();
 190   }
 191 
 192                                 // Does nothing for resource and arena objects
 193   ~GrowableArray()              { if (on_C_heap()) clear_and_deallocate(); }
 194 
 195   void  clear()                 { _len = 0; }
 196   int   length() const          { return _len; }

 197   void  trunc_to(int l)         { assert(l <= _len,"cannot increase length"); _len = l; }
 198   bool  is_empty() const        { return _len == 0; }
 199   bool  is_nonempty() const     { return _len != 0; }
 200   bool  is_full() const         { return _len == _max; }
 201   DEBUG_ONLY(E* data_addr() const      { return _data; })
 202 
 203   void print();
 204 
 205   int append(const E& elem) {
 206     check_nesting();
 207     if (_len == _max) grow(_len);
 208     int idx = _len++;
 209     _data[idx] = elem;
 210     return idx;
 211   }
 212 
 213   bool append_if_missing(const E& elem) {
 214     // Returns TRUE if elem is added.
 215     bool missed = !contains(elem);
 216     if (missed) append(elem);




 177   }
 178 
 179   GrowableArray(Arena* arena, int initial_size, int initial_len, const E& filler) : GenericGrowableArray(arena, initial_size, initial_len) {
 180     _data = (E*)raw_allocate(sizeof(E));
 181     int i = 0;
 182     for (; i < _len; i++) ::new ((void*)&_data[i]) E(filler);
 183     for (; i < _max; i++) ::new ((void*)&_data[i]) E();
 184   }
 185 
 186   GrowableArray() : GenericGrowableArray(2, 0, false) {
 187     _data = (E*)raw_allocate(sizeof(E));
 188     ::new ((void*)&_data[0]) E();
 189     ::new ((void*)&_data[1]) E();
 190   }
 191 
 192                                 // Does nothing for resource and arena objects
 193   ~GrowableArray()              { if (on_C_heap()) clear_and_deallocate(); }
 194 
 195   void  clear()                 { _len = 0; }
 196   int   length() const          { return _len; }
 197   int   max_length() const      { return _max; }
 198   void  trunc_to(int l)         { assert(l <= _len,"cannot increase length"); _len = l; }
 199   bool  is_empty() const        { return _len == 0; }
 200   bool  is_nonempty() const     { return _len != 0; }
 201   bool  is_full() const         { return _len == _max; }
 202   DEBUG_ONLY(E* data_addr() const      { return _data; })
 203 
 204   void print();
 205 
 206   int append(const E& elem) {
 207     check_nesting();
 208     if (_len == _max) grow(_len);
 209     int idx = _len++;
 210     _data[idx] = elem;
 211     return idx;
 212   }
 213 
 214   bool append_if_missing(const E& elem) {
 215     // Returns TRUE if elem is added.
 216     bool missed = !contains(elem);
 217     if (missed) append(elem);