Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
if i have a line of code like this:
if(a=b,1,
if(c=f,2,
if(c=g,3,4)))
my ?: if first condition is true (i.e.a=b) does the engine (parser) still waste it's time and slow stuff down by checking the remaining condiions?
Hi there,
I've had that problem as well. Use strings and evaluate the result works fine as a workaround when using CPU costly expressions. Ex:
If(a=1,
<expression 1>,
If(a=2,
<expression 2>,
If(a=3,
<expression 3>,
//else
<expression 4>
)))
you may convert every single expression to its string equivalent and $ at the end:
$(=
If(a=1,
<stringified expression 1>,
If(a=2,
<stringified expression 2>,
If(a=3,
<stringified expression 3>,
//else
<stringified expression 4>
)))
)
What you win: Only evaluate four strings (instead of four costly expressions) and only one costly expression instead of four.
How do you feel about this approach?