Re: [Wicket-user] adding children

2005-09-25 Thread Johan Compagner
yes it could but no for the second child
Then we have to have another check for this
Because the first child is just set as this.children

when the second child is added then this.children is not an array
so we need the current behaviour anyway
Only when adding the third (and more) we could use system array copy
But as i said then we have to do another check if the size()  1
but i don't think many performance will be reached by this. 
In the past i did some test but some times just looping was even faster then array copy
(because array copy is a native function with its native overhead)
Don't know the current status.
On 9/25/05, Justin Lee [EMAIL PROTECTED] wrote:
I was stepping through the wicket code trying to track down a problemwith my page when I ran across some code.InMarkupContainer.children_add()there's this code:if (this.children == null)
{this.children
= child;}else{//
Get current list sizefinal
int size = children_size();//
Create array that holds size + 1 elementsfinal
Component[] children = new Component[size + 1];//
Loop through existing children copying themfor
(int i = 0; i  size; i++){children[i]
= children_get(i);}//
Add new child to the endchildren[size]
= child;//
Save new childrenthis.children
= children;}It's look to me like a great case for System.arraycopy().Now, i'm notall that familiar with the code so maybe there's a good reason for this,but I don't think i've ever seen a loop like this outperform
System.arraycopy().And perhaps it could use a List or a Set ratherthan an array since many of the operations are already provided.Likewise children_get() does full array scans looking for an item by IDwhen using a map would give much better performance.But perhaps it was
decided that the lists would likely be small enough not to matter.ButI can see this kind of thing adding up to some significant time in somecases.Maybe there are some good decisions behind this code, but it
doesn't appear to be documented anywhere.Anyway, not to nit pick, I just saw that code and had to bring it up.--Justin Leehttp://www.antwerkz.comAIM : evan chooly
720.299.0101---SF.Net email is sponsored by:Tame your development challenges with Apache's Geronimo App Server. Downloadit for free - -and be entered to win a 42 plasma tv or your very own
Sony(tm)PSP.Click here to play: http://sourceforge.net/geronimo.php___Wicket-user mailing list
Wicket-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/wicket-user


[Wicket-user] adding children

2005-09-24 Thread Justin Lee
I was stepping through the wicket code trying to track down a problem 
with my page when I ran across some code.  In 
MarkupContainer.children_add()  there's this code:


if (this.children == null)
{
this.children = child;
}
else
{
// Get current list size
final int size = children_size();

// Create array that holds size + 1 elements
final Component[] children = new Component[size + 1];

// Loop through existing children copying them
for (int i = 0; i  size; i++)
{
children[i] = children_get(i);
}

// Add new child to the end
children[size] = child;

// Save new children
this.children = children;
}

It's look to me like a great case for System.arraycopy().  Now, i'm not 
all that familiar with the code so maybe there's a good reason for this, 
but I don't think i've ever seen a loop like this outperform 
System.arraycopy().  And perhaps it could use a List or a Set rather 
than an array since many of the operations are already provided. 
Likewise children_get() does full array scans looking for an item by ID 
when using a map would give much better performance.  But perhaps it was 
decided that the lists would likely be small enough not to matter.  But 
I can see this kind of thing adding up to some significant time in some 
cases.  Maybe there are some good decisions behind this code, but it 
doesn't appear to be documented anywhere.


Anyway, not to nit pick, I just saw that code and had to bring it up.

--
Justin Lee
http://www.antwerkz.com
AIM : evan chooly
720.299.0101


---
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42 plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user