src/share/vm/utilities/growableArray.hpp

changeset 867
275a3b7ff0d6
parent 435
a61af66fc99e
child 905
ad8c8ca4ab0f
     1.1 --- a/src/share/vm/utilities/growableArray.hpp	Wed Nov 12 22:33:26 2008 -0800
     1.2 +++ b/src/share/vm/utilities/growableArray.hpp	Wed Nov 12 23:26:45 2008 -0800
     1.3 @@ -111,6 +111,12 @@
     1.4    }
     1.5  
     1.6    void* raw_allocate(int elementSize);
     1.7 +
     1.8 +  // some uses pass the Thread explicitly for speed (4990299 tuning)
     1.9 +  void* raw_allocate(Thread* thread, int elementSize) {
    1.10 +    assert(on_stack(), "fast ResourceObj path only");
    1.11 +    return (void*)resource_allocate_bytes(thread, elementSize * _max);
    1.12 +  }
    1.13  };
    1.14  
    1.15  template<class E> class GrowableArray : public GenericGrowableArray {
    1.16 @@ -121,6 +127,11 @@
    1.17    void raw_at_put_grow(int i, const E& p, const E& fill);
    1.18    void  clear_and_deallocate();
    1.19   public:
    1.20 +  GrowableArray(Thread* thread, int initial_size) : GenericGrowableArray(initial_size, 0, false) {
    1.21 +    _data = (E*)raw_allocate(thread, sizeof(E));
    1.22 +    for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
    1.23 +  }
    1.24 +
    1.25    GrowableArray(int initial_size, bool C_heap = false) : GenericGrowableArray(initial_size, 0, C_heap) {
    1.26      _data = (E*)raw_allocate(sizeof(E));
    1.27      for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E();
    1.28 @@ -159,10 +170,12 @@
    1.29  
    1.30    void print();
    1.31  
    1.32 -  void append(const E& elem) {
    1.33 +  int append(const E& elem) {
    1.34      check_nesting();
    1.35      if (_len == _max) grow(_len);
    1.36 -    _data[_len++] = elem;
    1.37 +    int idx = _len++;
    1.38 +    _data[idx] = elem;
    1.39 +    return idx;
    1.40    }
    1.41  
    1.42    void append_if_missing(const E& elem) {

mercurial