Optimisation by saving a function per loop iteration

Sun, 21 Jun 2009 19:16:54 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 21 Jun 2009 19:16:54 +0100
changeset 11
a40db377a1b5
parent 10
6700d4722be7
child 12
a127265f3257

Optimisation by saving a function per loop iteration

ndp.lua file | annotate | diff | comparison | revisions
--- a/ndp.lua	Sun Jun 21 19:13:16 2009 +0100
+++ b/ndp.lua	Sun Jun 21 19:16:54 2009 +0100
@@ -157,9 +157,9 @@
 	}
 	
 	local ret, min_pos, max_pos;
+	local function check_min_pos(start) start = start - 1; if not min_pos or start < min_pos then min_pos = start; end end;
 	for _, pattern in pairs(patterns) do
-		ret = lpeg.match(lpeg.P{ lpeg.Cp()*pattern[1] + 1 * lpeg.V(1) }
-		/function (start) start = start - 1; if not min_pos or start < min_pos then min_pos = start; end end, str);
+		ret = lpeg.match(lpeg.P{ lpeg.Cp()*pattern[1] + 1 * lpeg.V(1) }/check_min_pos, str);
 		if ret then
 			if not max_pos or ret > max_pos then max_pos = ret; end
 			--print("Matches ".._.." until "..ret);

mercurial