145 assert(on_stack(), "fast ResourceObj path only"); |
145 assert(on_stack(), "fast ResourceObj path only"); |
146 return (void*)resource_allocate_bytes(thread, elementSize * _max); |
146 return (void*)resource_allocate_bytes(thread, elementSize * _max); |
147 } |
147 } |
148 }; |
148 }; |
149 |
149 |
|
150 template<class E> class GrowableArrayIterator; |
|
151 template<class E, class UnaryPredicate> class GrowableArrayFilterIterator; |
|
152 |
150 template<class E> class GrowableArray : public GenericGrowableArray { |
153 template<class E> class GrowableArray : public GenericGrowableArray { |
151 friend class VMStructs; |
154 friend class VMStructs; |
152 |
155 |
153 private: |
156 private: |
154 E* _data; // data array |
157 E* _data; // data array |
410 tty->print(": length %ld (_max %ld) { ", _len, _max); |
421 tty->print(": length %ld (_max %ld) { ", _len, _max); |
411 for (int i = 0; i < _len; i++) tty->print(INTPTR_FORMAT " ", *(intptr_t*)&(_data[i])); |
422 for (int i = 0; i < _len; i++) tty->print(INTPTR_FORMAT " ", *(intptr_t*)&(_data[i])); |
412 tty->print("}\n"); |
423 tty->print("}\n"); |
413 } |
424 } |
414 |
425 |
|
426 // Custom STL-style iterator to iterate over GrowableArrays |
|
427 // It is constructed by invoking GrowableArray::begin() and GrowableArray::end() |
|
428 template<class E> class GrowableArrayIterator : public StackObj { |
|
429 friend class GrowableArray<E>; |
|
430 template<class F, class UnaryPredicate> friend class GrowableArrayFilterIterator; |
|
431 |
|
432 private: |
|
433 const GrowableArray<E>* _array; // GrowableArray we iterate over |
|
434 int _position; // The current position in the GrowableArray |
|
435 |
|
436 // Private constructor used in GrowableArray::begin() and GrowableArray::end() |
|
437 GrowableArrayIterator(const GrowableArray<E>* array, int position) : _array(array), _position(position) { |
|
438 assert(0 <= position && position <= _array->length(), "illegal position"); |
|
439 } |
|
440 |
|
441 public: |
|
442 GrowableArrayIterator<E>& operator++() { ++_position; return *this; } |
|
443 E operator*() { return _array->at(_position); } |
|
444 |
|
445 bool operator==(const GrowableArrayIterator<E>& rhs) { |
|
446 assert(_array == rhs._array, "iterator belongs to different array"); |
|
447 return _position == rhs._position; |
|
448 } |
|
449 |
|
450 bool operator!=(const GrowableArrayIterator<E>& rhs) { |
|
451 assert(_array == rhs._array, "iterator belongs to different array"); |
|
452 return _position != rhs._position; |
|
453 } |
|
454 }; |
|
455 |
|
456 // Custom STL-style iterator to iterate over elements of a GrowableArray that satisfy a given predicate |
|
457 template<class E, class UnaryPredicate> class GrowableArrayFilterIterator : public StackObj { |
|
458 friend class GrowableArray<E>; |
|
459 |
|
460 private: |
|
461 const GrowableArray<E>* _array; // GrowableArray we iterate over |
|
462 int _position; // Current position in the GrowableArray |
|
463 UnaryPredicate _predicate; // Unary predicate the elements of the GrowableArray should satisfy |
|
464 |
|
465 public: |
|
466 GrowableArrayFilterIterator(const GrowableArrayIterator<E>& begin, UnaryPredicate filter_predicate) |
|
467 : _array(begin._array), _position(begin._position), _predicate(filter_predicate) { |
|
468 // Advance to first element satisfying the predicate |
|
469 while(_position != _array->length() && !_predicate(_array->at(_position))) { |
|
470 ++_position; |
|
471 } |
|
472 } |
|
473 |
|
474 GrowableArrayFilterIterator<E, UnaryPredicate>& operator++() { |
|
475 do { |
|
476 // Advance to next element satisfying the predicate |
|
477 ++_position; |
|
478 } while(_position != _array->length() && !_predicate(_array->at(_position))); |
|
479 return *this; |
|
480 } |
|
481 |
|
482 E operator*() { return _array->at(_position); } |
|
483 |
|
484 bool operator==(const GrowableArrayIterator<E>& rhs) { |
|
485 assert(_array == rhs._array, "iterator belongs to different array"); |
|
486 return _position == rhs._position; |
|
487 } |
|
488 |
|
489 bool operator!=(const GrowableArrayIterator<E>& rhs) { |
|
490 assert(_array == rhs._array, "iterator belongs to different array"); |
|
491 return _position != rhs._position; |
|
492 } |
|
493 |
|
494 bool operator==(const GrowableArrayFilterIterator<E, UnaryPredicate>& rhs) { |
|
495 assert(_array == rhs._array, "iterator belongs to different array"); |
|
496 return _position == rhs._position; |
|
497 } |
|
498 |
|
499 bool operator!=(const GrowableArrayFilterIterator<E, UnaryPredicate>& rhs) { |
|
500 assert(_array == rhs._array, "iterator belongs to different array"); |
|
501 return _position != rhs._position; |
|
502 } |
|
503 }; |
|
504 |
415 #endif // SHARE_VM_UTILITIES_GROWABLEARRAY_HPP |
505 #endif // SHARE_VM_UTILITIES_GROWABLEARRAY_HPP |