View Single Post
07/03/14, 01:14 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
My guess on what the OP is asking is this: (Again, just a guess, as the OP wasn't very clear.)

Lua Code:
  1. function DoStuff()
  2.      if myTable.var == "something" then
  3.           OtherFunction(myTable.var)
  4.      elseif myTable.var == "somethingelse" then
  5.           NextFunction(myTable.var)
  6.      else
  7.           LastFunction(myTable.var)
  8.      end
  9. end

In the above pseudo-code, you are looking up the value of myTable.var 5 times. In this case, it would be more efficient to assign the value to a local variable and do this instead:
Lua Code:
  1. function DoStuff()
  2.      local var = myTable.var
  3.      if var == "something" then
  4.           OtherFunction(var)
  5.      elseif var == "somethingelse" then
  6.           NextFunction(var)
  7.      else
  8.           LastFunction(var)
  9.      end
  10. end

Granted, the gain is minimal unless this code is being executed at a high rate, such as for every OnUpdate or for an event that fires often.
  Reply With Quote