I have an issue, to the tune of 80 KB of junk every time COMPANION_UPDATE fires.
For
my addon, I find it necessary to keep up to date information on your companions. Beyond simply registering COMPANION_UPDATE and calling GetCompanionInfo, I also pull some extra data from tooltips and hard-coded tables, in order to offer more information to the user (such as mount speed).
The issues arose when I added in the capacity to
sort that data. Three columns
appear in the display, and the tabs at the top of each enable sorting, much like the Guild or Who frames. To allow for this behavior, I found it necessary to store several pieces of information in a table, which I could later sort, and whenever the display needed to be refreshed, I read off the appropriate rows from the table. The problem appears to lie in the need to rebuild the entire table every time that COMPANION_UPDATE fires (very common in cities, as it fires for nearby players as well).
What recommendations might you have to offer to cut down on the garbage generation inherent to this approach? What alternative approaches might exist?
lua Code:
local MountData = {}
local function UpdateMountData()
MountData = {}
local creatureName, spellID, icon, active
local speed, mountType, numPassengers, isUsable, varies
local notes
for i=1, GetNumCompanions("MOUNT") do
notes = ""
_, creatureName, spellID, icon, active = GetCompanionInfo("MOUNT", i)
-- GetExtraCompanionData is my function that does the tooltip scanning and such
speed, mountType, numPassengers, isUsable, varies = unpack(GetExtraCompanionData("MOUNT", spellID),1,5)
if numPassengers > 0 then
-- NOTE: addLine is just a utility function to insert newlines as appropriate
notes = addLine(notes, format(L["Passengers: %d"], numPassengers))
end
if varies then
notes = addLine(notes, L["Varies"])
end
if not strfind(notes, "\n") then
if mountType == MOUNTTYPE_LAND then
notes = addLine(notes, L["Ground"])
elseif mountType == MOUNTTYPE_FLYING then
notes = addLine(notes, L["Flying"])
elseif mountType == MOUNTTYPE_AQUATIC then
notes = addLine(notes, L["Aquatic"])
end
end
tinsert(MountData, {NAME = creatureName, NOTES = notes, SPEED = speed, ICON = icon, ACTIVE = active, ISUSABLE = isUsable, ID = i})
end
end