# HG changeset patch # User Waqas Hussain # Date 1279120235 -18000 # Node ID 32dc830d976c07d549a7791dede9d8bae0311dd4 # Parent 6a5d779249498107b0df595ed801c31037e788df util.sasl, util.sasl_cyrus: Updated method:mechanisms() to cache and re-use list of mechanisms. diff -r 6a5d77924949 -r 32dc830d976c util/sasl.lua --- a/util/sasl.lua Wed Jul 14 20:05:25 2010 +0500 +++ b/util/sasl.lua Wed Jul 14 20:10:35 2010 +0500 @@ -88,17 +88,20 @@ -- get a list of possible SASL mechanims to use function method:mechanisms() - local mechanisms = {} - for backend, f in pairs(self.profile) do - if backend_mechanism[backend] then - for _, mechanism in ipairs(backend_mechanism[backend]) do - if not self.restrict:contains(mechanism) then - mechanisms[mechanism] = true; + local mechanisms = self.mechs; + if not mechanisms then + mechanisms = {} + for backend, f in pairs(self.profile) do + if backend_mechanism[backend] then + for _, mechanism in ipairs(backend_mechanism[backend]) do + if not self.restrict:contains(mechanism) then + mechanisms[mechanism] = true; + end end end end + self.mechs = mechanisms; end - self.mechs = mechanisms; return mechanisms; end diff -r 6a5d77924949 -r 32dc830d976c util/sasl_cyrus.lua --- a/util/sasl_cyrus.lua Wed Jul 14 20:05:25 2010 +0500 +++ b/util/sasl_cyrus.lua Wed Jul 14 20:10:35 2010 +0500 @@ -129,12 +129,15 @@ -- get a list of possible SASL mechanims to use function method:mechanisms() - local mechanisms = {} - local cyrus_mechs = cyrussasl.listmech(self.cyrus, nil, "", " ", "") - for w in s_gmatch(cyrus_mechs, "[^ ]+") do - mechanisms[w] = true; + local mechanisms = self.mechs; + if not mechanisms then + mechanisms = {} + local cyrus_mechs = cyrussasl.listmech(self.cyrus, nil, "", " ", "") + for w in s_gmatch(cyrus_mechs, "[^ ]+") do + mechanisms[w] = true; + end + self.mechs = mechanisms end - self.mechs = mechanisms return mechanisms; end