I applied the same optimization that I did for JComponent to the
LightweightDispatcher, as this seems performance critical.
2006-07-07 Roman Kennke <[EMAIL PROTECTED]>
* java/awt/LightweightDispatcher.java
(findTarget): Avoid array copying in
Container.getComponents().
/Roman
Index: java/awt/LightweightDispatcher.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/LightweightDispatcher.java,v
retrieving revision 1.10
diff -u -1 -2 -r1.10 LightweightDispatcher.java
--- java/awt/LightweightDispatcher.java 8 Jun 2006 16:10:30 -0000 1.10
+++ java/awt/LightweightDispatcher.java 7 Jul 2006 12:49:41 -0000
@@ -278,31 +278,31 @@
* one which is showing, at the location from the mouse event and has
* a MouseListener or MouseMotionListener attached. If no such child component
* is found, null is returned.
*
* @param c the container to search through
* @param loc the mouse event point
*
* @return the actual receiver of the mouse event, or null, if no such
* component has been found
*/
private Component findTarget(Container c, Point loc)
{
- Component[] children = c.getComponents();
+ int numComponents = c.getComponentCount();
Component target = null;
if (c != null)
{
- for (int i = 0; i < children.length; i++)
+ for (int i = 0; i < numComponents; i++)
{
- Component child = children[i];
+ Component child = c.getComponent(i);
if (child.isShowing())
{
if (child.contains(loc.x - child.getX(), loc.y - child.getY())
&& (child.getMouseListeners().length > 0
|| child.getMouseMotionListeners().length > 0))
{
target = child;
break;
}
}
}
}