View Single Post
10-31-22, 04:11 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,336
Originally Posted by tehmoku View Post
I would like to see your optimizations though. I threw it together pretty quick, and I can already see at least one thing I'd change, but I might as well optimize as much as I can if I'm going to handle the numbers myself (although I don't know if that's specifically worth it...)
The first thing that stood out to me was this line.
Code:
local timeLeft = start / 1000 + dur / 1000 - GetTime()
Currently, you're taking one variable, dividing by 1000, then taking another variable and doing the same before adding them together. You can save a divide operation by adding the variables together before dividing by 1000.
Code:
local timeLeft = (start + dur) / 1000 - GetTime()


A second thing I'd note is FontStrings have a built-in format function that works in the same way, you can save a global index and a function call by using it instead. Even if C code does the exact same thing, remember, C code processes much faster natively than Lua code can.
Code:
self.text:SetFormattedText("%d", timeLeft)


Again, and at the scale of once every 200ms, you're not really going to see a difference.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-31-22 at 04:22 PM.
  Reply With Quote