Add Reset method to Pool modules that re-initializes to empty states.
Johnny C. Lam [08-10-13 - 18:38]
Add Reset method to Pool modules that re-initializes to empty states.
git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@994 d5049fe3-3747-40f7-a4b5-f36d6801af5f
diff --git a/OvalePool.lua b/OvalePool.lua
index 925bf93..1453772 100644
--- a/OvalePool.lua
+++ b/OvalePool.lua
@@ -21,8 +21,9 @@ OvalePool.unused = 0
--<public-static-methods>
function OvalePool:NewPool(name)
- obj = { name = name, pool = {}, size = 0, unused = 0 }
+ obj = { name = name }
setmetatable(obj, { __index = self })
+ obj:Reset()
return obj
end
@@ -56,6 +57,12 @@ function OvalePool:Drain()
self.unused = 0
end
+function OvalePool:Reset()
+ self.pool = {}
+ self.size = 0
+ self.unused = 0
+end
+
function OvalePool:Debug()
Ovale:FormatPrint("Pool %s has size %d with %d item(s).", self.name, self.size, self.unused)
end
diff --git a/OvalePoolGC.lua b/OvalePoolGC.lua
index b486011..13bce90 100644
--- a/OvalePoolGC.lua
+++ b/OvalePoolGC.lua
@@ -21,8 +21,9 @@ OvalePoolGC.unused = 0
--<public-static-methods>
function OvalePoolGC:NewPool(name)
- obj = { name = name, size = 0, unused = 0 }
+ obj = { name = name }
setmetatable(obj, { __index = self })
+ obj:Reset()
return obj
end
@@ -36,6 +37,11 @@ end
function OvalePoolGC:Release(item) end
function OvalePoolGC:Drain() end
+function OvalePoolGC:Reset()
+ self.size = 0
+ self.unused = 0
+end
+
function OvalePoolGC:Debug()
Ovale:FormatPrint("Pool %s has size %d.", self.name, self.size)
end