View Single Post
04-13-13, 01:36 PM   #24
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Calling a function is pretty much the slowest thing you can do. It's even faster to do three table lookups:

Code:
local color = { 1, 0, 1 }
local r, g, b = color[1], color[2], color[3]
... than to do one function call:

Code:
local color = { 1, 0, 1 }
local r, g, b = unpack(color)
... even if you've upvalued the function.

Since select can be avoided in pretty much every single case, you should avoid it. Do this:

Code:
local _, _, _, _, _, var = GetSomeValues()
print(var)
... instead of this:

Code:
print((select(6, GetSomeValues()))
The former may be "more code" but it's faster, and more readable, and definitely more efficient if you're using other values returned by the same function -- I've seen some addons where the same function is called multiple times in a row, wrapped in different select calls. Huge waste of CPU time.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 04-13-13 at 01:38 PM.
  Reply With Quote