Mercurial > hg > truffle
comparison src/share/vm/utilities/growableArray.hpp @ 432:275a3b7ff0d6
6770949: minor tweaks before 6655638
Summary: minor cleanups & tuning of array.hpp, debug.cpp, growableArray.hpp, hashtable.cpp
Reviewed-by: kvn
author | jrose |
---|---|
date | Wed, 12 Nov 2008 23:26:45 -0800 |
parents | a61af66fc99e |
children | ad8c8ca4ab0f |
comparison
equal
deleted
inserted
replaced
431:a45484ea312d | 432:275a3b7ff0d6 |
---|---|
109 _arena = arena; | 109 _arena = arena; |
110 assert(on_arena(), "arena has taken on reserved value 0 or 1"); | 110 assert(on_arena(), "arena has taken on reserved value 0 or 1"); |
111 } | 111 } |
112 | 112 |
113 void* raw_allocate(int elementSize); | 113 void* raw_allocate(int elementSize); |
114 | |
115 // some uses pass the Thread explicitly for speed (4990299 tuning) | |
116 void* raw_allocate(Thread* thread, int elementSize) { | |
117 assert(on_stack(), "fast ResourceObj path only"); | |
118 return (void*)resource_allocate_bytes(thread, elementSize * _max); | |
119 } | |
114 }; | 120 }; |
115 | 121 |
116 template<class E> class GrowableArray : public GenericGrowableArray { | 122 template<class E> class GrowableArray : public GenericGrowableArray { |
117 private: | 123 private: |
118 E* _data; // data array | 124 E* _data; // data array |
119 | 125 |
120 void grow(int j); | 126 void grow(int j); |
121 void raw_at_put_grow(int i, const E& p, const E& fill); | 127 void raw_at_put_grow(int i, const E& p, const E& fill); |
122 void clear_and_deallocate(); | 128 void clear_and_deallocate(); |
123 public: | 129 public: |
130 GrowableArray(Thread* thread, int initial_size) : GenericGrowableArray(initial_size, 0, false) { | |
131 _data = (E*)raw_allocate(thread, sizeof(E)); | |
132 for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); | |
133 } | |
134 | |
124 GrowableArray(int initial_size, bool C_heap = false) : GenericGrowableArray(initial_size, 0, C_heap) { | 135 GrowableArray(int initial_size, bool C_heap = false) : GenericGrowableArray(initial_size, 0, C_heap) { |
125 _data = (E*)raw_allocate(sizeof(E)); | 136 _data = (E*)raw_allocate(sizeof(E)); |
126 for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); | 137 for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); |
127 } | 138 } |
128 | 139 |
157 bool is_full() const { return _len == _max; } | 168 bool is_full() const { return _len == _max; } |
158 DEBUG_ONLY(E* data_addr() const { return _data; }) | 169 DEBUG_ONLY(E* data_addr() const { return _data; }) |
159 | 170 |
160 void print(); | 171 void print(); |
161 | 172 |
162 void append(const E& elem) { | 173 int append(const E& elem) { |
163 check_nesting(); | 174 check_nesting(); |
164 if (_len == _max) grow(_len); | 175 if (_len == _max) grow(_len); |
165 _data[_len++] = elem; | 176 int idx = _len++; |
177 _data[idx] = elem; | |
178 return idx; | |
166 } | 179 } |
167 | 180 |
168 void append_if_missing(const E& elem) { | 181 void append_if_missing(const E& elem) { |
169 if (!contains(elem)) append(elem); | 182 if (!contains(elem)) append(elem); |
170 } | 183 } |