|
![](/i/fill.gif) |
Thorsten Froehlich wrote:
> In article <3bb37e54$1@news.povray.org> , "Thorsten Froehlich"
> <tho### [at] trf de> wrote:
>
>> By using the original search direction and a third variable it might well
>> be that there is a more efficient solution so parsing is faster if the
>> above is done on huge arrays with only a very few zeros.
>
> Actually, the code below should work (didn't bother to test it) and be
> much faster in most cases.
>
> #macro findzero(a, n)
> #local i = 0;
> #while(i <= n)
> #if(a[i] != 0)
> #declare n = i;
> #end
> #declare i = i + 1;
> #end
> #end
Nice idea to traverse the array from the end.. but as you already noticed
it is less efficient. But you two variables all the same.. with my example
'n' has been a constant and the result was returned in the only changed
variable 'i'. And I still think that the variant with usage of
short-circuit evaluation is nicer... it is shorter, more efficient, and if
somebody looks at it he/she instantly sees what it does.
Where I got to this problem was some problem of sorting a special array
with many same values and a special pre-order. It was only thought as an
example why I prefered short-circ eval.
That still leaves the question open if other people are unhappy as well
with the current evaulation type.
- Micha
Post a reply to this message
|
![](/i/fill.gif) |