Quantcast

Use a more efficient method to replace constants with values.

Johnny C. Lam [10-19-12 - 01:38]
Use a more efficient method to replace constants with values.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@606 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleCompile.lua
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index 5aaff7c..dc18ec6 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -361,18 +361,6 @@ local function ParseGroup(text)
 	return AddNode(newNode)
 end

-local function subtest(text, pattern, func)
-	while (1==1) do
-		local was = text
-		text = strgsub(text, pattern, func)
-		if (was == text) then
-			break
-		end
-	end
-	return text
-end
-
-
 local function ParseAddListItem(list, item, text, params)
 	local paramList = ParseParameters(params)
 	if not TestConditions(paramList) then
@@ -388,7 +376,6 @@ local function ParseAddListItem(list, item, text, params)
 	return ""
 end

-
 local function ParseAddCheckBox(item, text, params)
 	local paramList = ParseParameters(params)
 	if not TestConditions(paramList) then
@@ -409,6 +396,10 @@ local function ParseDefine(key, value)
 	return ""
 end

+local function ReplaceDefine(key)
+	return defines[key]
+end
+
 local function ParseLua(text)
 	local newNode = {type="lua", lua = strsub(text, 2, strlen(text)-1)}
 	return AddNode(newNode)
@@ -540,9 +531,7 @@ function OvaleCompile:CompileDeclarations(text)
 	text = strgsub(text, "Define%s*%(%s*([%w_]+)%s+(%w+)%s*%)", ParseDefine)

 	-- On remplace les constantes par leur valeur
-	for k,v in pairs(defines) do
-		text = subtest(text, "([^%w_])"..k.."([^%w_])", "%1"..v.."%2")
-	end
+	text = strgsub(text, "([%w_]+)", ReplaceDefine)

 	-- Fonctions
 	text = strgsub(text, "SpellName%s*%(%s*(%w+)%s*%)", ParseSpellName)