util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms table).

Wed, 29 Dec 2010 18:45:31 +0500

author
Waqas Hussain <waqas20@gmail.com>
date
Wed, 29 Dec 2010 18:45:31 +0500
changeset 3986
671a660b20f9
parent 3985
277b5bf9a200
child 3987
8fbf57722368

util.sasl: Cache the calculated mechanisms set for SASL profiles (profile.mechanisms table).

util/sasl.lua file | annotate | diff | comparison | revisions
--- a/util/sasl.lua	Tue Dec 28 09:59:27 2010 +0500
+++ b/util/sasl.lua	Wed Dec 29 18:45:31 2010 +0500
@@ -48,13 +48,17 @@
 
 -- create a new SASL object which can be used to authenticate clients
 function new(realm, profile)
-	local mechanisms = {};
-	for backend, f in pairs(profile) do
-		if backend_mechanism[backend] then
-			for _, mechanism in ipairs(backend_mechanism[backend]) do
-				mechanisms[mechanism] = true;
+	local mechanisms = profile.mechanisms;
+	if not mechanisms then
+		mechanisms = {};
+		for backend, f in pairs(profile) do
+			if backend_mechanism[backend] then
+				for _, mechanism in ipairs(backend_mechanism[backend]) do
+					mechanisms[mechanism] = true;
+				end
 			end
 		end
+		profile.mechanisms = mechanisms;
 	end
 	return setmetatable({ profile = profile, realm = realm, mechs = mechanisms }, method);
 end

mercurial