Name: diC59631 Date: 02/16/98
The following code (share/java/java/awt/Container.java) seems to be doing a lot
of arraycopy and reallocation of arrays by doubling the arraysize.
I wonder why it cant be implemented as component list, where
- no need to allocate such big array by doubling the arraysize
- insertion of components becomes easier
- no array copies.
- Specially, in the case of embedded platforms, it would use more memory and
may be would be less efficient.
For ex. if I consider 50 components to be inserted in some random order, it would
- reallocate arrays 5 times
- Garbage collection a no. of times &
- arraycopy more than 50 times.
This delay just multiplies
/* Add component to list; allocate new array if necessary. */
if (ncomponents == component.length) {
Component newcomponents[] = new Component[ncomponents * 2];
System.arraycopy(component, 0, newcomponents, 0, ncomponents);
component = newcomponents;
}
if (index == -1 || index == ncomponents) {
component[ncomponents++] = comp;
} else {
System.arraycopy(component, index, component,
index + 1, ncomponents - index);
component[index] = comp;
ncomponents++;
}
(Review ID: 25082)
======================================================================