On 2011-03-11 11:43, Ricky wrote:
Thanks for the review! Yes, I am familiar with those "principles of
optimization" - yet it seemed to just feel wrong to leave it alone... :P
As to the variables that are initialized with high numbers, there has
to be a better way: if these were standard for-loops, I would just
initialize the first value with the first item in the list, and then
start the loop at the second value, if any. However, these are a
iterator style I am not yet familiar enough with to bend that far.
Any suggestions?
When I write a for loop that has multiple control variables, I use comma
expressions. For example, if I wanted to iterate over selections and
operate on the first MAX_SELECTIONS or until there were not any more one
could put the count outside the loop:
S32 counter = 0;
LLObjectSelection::root_iterator it;
for (it = getSelection()->root_begin();
it != getSelection()->root_end();
++it)
{
if (counter>= MAX_SELECTIONS)
{
break;
}
// whatever it is the loop does
counter++;
}
One could make that better by moving the counter test up into the second
expression in the for loop, but I'd take the extra step of also putting
the initialization and increments of both variables into the for:
S32 counter;
LLObjectSelection::root_iterator it;
for (it = getSelection()->root_begin(), counter = 0;
it != getSelection()->root_end()&& counter< MAX_SELECTIONS;
++it, ++counter)
{
// whatever it is the loop does
}
I think that makes it clearer that both variables are controlling the loop.
Comma expressions are not seen all that often (this sort if thing is the
only really good application of them I can think of), but I've never
found a compiler that didn't support them correctly.
_______________________________________________
Policies and (un)subscribe information available here:
http://wiki.secondlife.com/wiki/OpenSource-Dev
Please read the policies before posting to keep unmoderated posting privileges