diff Modules/Summary.lua @ 122:6724bc8eface

Reduced usage of global functions by defining them locally.
author Zerotorescue
date Sat, 15 Jan 2011 18:52:01 +0100
parents d3fbb5676a5e
children 396c2960d54d
line wrap: on
line diff
--- a/Modules/Summary.lua	Sat Jan 15 17:09:13 2011 +0100
+++ b/Modules/Summary.lua	Sat Jan 15 18:52:01 2011 +0100
@@ -1,14 +1,15 @@
 local addon = select(2, ...); -- Get a reference to the main addon object
 local mod = addon:NewModule("Summary", "AceEvent-3.0", "AceTimer-3.0"); -- register a new module, Summary: resposible for building the summary window
 
+local _G = _G; -- prevent looking up of the global table
+local sformat, sgsub, supper, mceil, mfloor, tinsert, twipe, tsort = _G.string.format, _G.string.gsub, _G.string.upper, _G.math.ceil, _G.math.floor, _G.table.insert, _G.table.wipe, _G.table.sort;
+local pairs, type, select = _G.pairs, _G.type, _G.select;
+
 local unknownItemName = "Unknown (#%d)";
 
 local CACHE_ITEMS_TOTAL, CACHE_ITEMS_CURRENT, itemsCache = 0, 0, {};
 local AceGUI, cacheStart;
 
-local _G = _G; -- prevent looking up of the global table
-local sformat, sgsub, supper, tinsert, pairs, ceil, GetItemInfo = _G.string.format, _G.string.gsub, _G.string.upper, _G.table.insert, _G.pairs, _G.ceil, _G.GetItemInfo; -- prevent looking up of the most used globals all the time
-
 function mod:OnEnable()
 	-- Register the summary specific widget
 	addon:GetModule("Widgets"):InlineGroupWithButton();
@@ -85,7 +86,7 @@
 	mod.frame:AddChild(mod.scrollFrame);
 	
 	-- Reset items cache
-	table.wipe(itemsCache);
+	twipe(itemsCache);
 end
 
 function mod:CloseFrame()
@@ -121,7 +122,7 @@
 local function pairsByKeys (t, f)
 	local a = {}
 	for n in pairs(t) do tinsert(a, n) end
-		table.sort(a, f)
+		tsort(a, f)
 	local i = 0      -- iterator variable
 	local iter = function ()   -- iterator function
 		i = i + 1
@@ -147,7 +148,7 @@
 	btnRefresh:SetRelativeWidth(.2);
 	btnRefresh:SetCallback("OnClick", function()
 		-- Reset items cache
-		table.wipe(itemsCache);
+		twipe(itemsCache);
 		
 		-- Rebuild itemlist and start caching
 		mod:Build();
@@ -171,9 +172,7 @@
 	sdrSpeed:SetIsPercent(true);
 	sdrSpeed:SetRelativeWidth(.3);
 	sdrSpeed:SetCallback("OnMouseUp", function(self, event, value)
-		addon.db.profile.defaults.summary.speed = ceil( ( ( value * 100 ) / 5) - .5 );
-		
-		CACHE_ITEMS_PER_UPDATE = addon.db.profile.defaults.summary.speed; -- max = 20, min = 1
+		addon.db.profile.defaults.summary.speed = mceil( ( ( value * 100 ) / 5) - .5 );
 	end);
 	sdrSpeed:SetValue( addon.db.profile.defaults.summary.speed * 5 / 100 );
 	sdrSpeed:SetCallback("OnEnter", ShowTooltip);
@@ -222,7 +221,7 @@
 	
 	mod.scrollFrame:AddChild(btnQueueAll);
 	
-	times.init = ceil( ( GetTime() - buildStartTime ) * 1000 );
+	times.init = mceil( ( GetTime() - buildStartTime ) * 1000 );
 	addon:Debug("Time spent legend: (init / sorting / preparing / building / all).");
 	
 	local playerName = UnitName("player");
@@ -339,12 +338,12 @@
 				end
 			end
 			
-			groupTimes.init = ceil( ( GetTime() - groupStartTime ) * 1000 );
+			groupTimes.init = mceil( ( GetTime() - groupStartTime ) * 1000 );
 			
 			
 			
 			-- Sort items
-			table.sort(itemsCache[groupName], function(a, b)
+			tsort(itemsCache[groupName], function(a, b)
 				local aRarity = a.rarity or 1;
 				local bRarity = b.rarity or 1;
 				
@@ -387,7 +386,7 @@
 				end
 			end);
 			
-			groupTimes.sorting = ceil( ( GetTime() - groupStartTime ) * 1000 );
+			groupTimes.sorting = mceil( ( GetTime() - groupStartTime ) * 1000 );
 			
 			
 			
@@ -448,23 +447,23 @@
 				end
 			end
 			
-			groupTimes.preparing = ceil( ( GetTime() - groupStartTime ) * 1000 );
+			groupTimes.preparing = mceil( ( GetTime() - groupStartTime ) * 1000 );
 			
 			iGroup:ResumeLayout();
 			mod.scrollFrame:AddChild(iGroup); -- this can take up to .5 seconds, might need to look into again at a later time
 			
-			groupTimes.building = ceil( ( GetTime() - groupStartTime ) * 1000 );
+			groupTimes.building = mceil( ( GetTime() - groupStartTime ) * 1000 );
 		end
 		
 		if groupStartTime and groupTimes then
-			addon:Debug("Building of %s took %d ms (%d / %d / %d / %d / %d).", groupName, ceil( ( GetTime() - groupStartTime ) * 1000 ), groupTimes.init or 0, groupTimes.sorting or 0, groupTimes.preparing or 0, groupTimes.building or 0, ceil( ( GetTime() - buildStartTime ) * 1000 ));
+			addon:Debug("Building of %s took %d ms (%d / %d / %d / %d / %d).", groupName, mceil( ( GetTime() - groupStartTime ) * 1000 ), groupTimes.init or 0, groupTimes.sorting or 0, groupTimes.preparing or 0, groupTimes.building or 0, mceil( ( GetTime() - buildStartTime ) * 1000 ));
 		end
 	end
 	
 	mod.scrollFrame:ResumeLayout();
 	mod.scrollFrame:DoLayout();
 	
-	addon:Debug("Done building summary after %d ms.", ceil( ( GetTime() - buildStartTime ) * 1000 ));
+	addon:Debug("Done building summary after %d ms.", mceil( ( GetTime() - buildStartTime ) * 1000 ));
 	
 	if CACHE_ITEMS_TOTAL > 0 then
 		cacheStart = GetTime();
@@ -517,7 +516,7 @@
 				CACHE_ITEMS_CURRENT = CACHE_ITEMS_CURRENT + 1;
 				
 				if mod.frame then
-					mod.frame:SetStatusText(sformat("Caching auction values and item-counts... %d%% has already been processed.", floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100)));
+					mod.frame:SetStatusText(sformat("Caching auction values and item-counts... %d%% has already been processed.", mfloor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100)));
 				end
 				
 				if i >= addon.db.profile.defaults.summary.speed then
@@ -538,7 +537,7 @@
 	self:Build();
 	
 	-- Announce
-	mod.frame:SetStatusText("All required prices and itemcounts have been cached. This process took " .. ceil(GetTime() - cacheStart) .. " seconds.");
+	mod.frame:SetStatusText("All required prices and itemcounts have been cached. This process took " .. mceil(GetTime() - cacheStart) .. " seconds.");
 	
 	-- Forget time
 	cacheStart = nil;
@@ -564,6 +563,7 @@
 
 function mod:NumberFormat(num)
 	local formatted = sgsub(num, "(%d)(%d%d%d)$", "%1,%2", 1);
+	local matches;
 	
 	while true do
 		formatted, matches = sgsub(formatted, "(%d)(%d%d%d),", "%1,%2,", 1);