From 81c3a58d1fed9f0e5713d005181b871c12843fd3 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 14 Jul 2010 20:10:35 +0500 Subject: util.sasl, util.sasl_cyrus: Updated method:mechanisms() to cache and re-use list of mechanisms. --- util/sasl.lua | 17 ++++++++++------- util/sasl_cyrus.lua | 13 ++++++++----- 2 files changed, 18 insertions(+), 12 deletions(-) (limited to 'util') diff --git a/util/sasl.lua b/util/sasl.lua index a7e151a2..8f91f7b5 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -88,17 +88,20 @@ end -- 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 --git a/util/sasl_cyrus.lua b/util/sasl_cyrus.lua index b03174f5..5178f7cd 100644 --- a/util/sasl_cyrus.lua +++ b/util/sasl_cyrus.lua @@ -129,12 +129,15 @@ end -- 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 -- cgit v1.2.3