For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

BaltoStar_12467's avatar
Nov 11, 2013

iRule optimization : store string evaluation as boolean

Is there any advantage to storing the result of a string comparison as a boolean ?

set query_params_exist ( [HTTP::query] ne "" )

if (query_params_exist == 1) {
}

... somewhere else deep in logic

if (query_params_exist == 1) {
}
`


Or perhaps this be shortened to : 

`if (query_params_exist) {
}

2 Replies

  • My understanding is that there is no advantage to storing the result as a variable rather than executing

    if {[HTTP::query] ne ""}
    

    multiple times.

  • you will shave cycles (small, but every bit helps) by using if { $variable } instead of if { $variable == 1 }, but there is no benefit to setting a variable to a value already cached in memory like HTTP::query unless you are performing additional operations against that value multiple times, then it makes sense to set the variable.