aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-12-01 02:25:25 +0100
committerKim Alvefur <zash@zash.se>2017-12-01 02:25:25 +0100
commit4202df3e79ad611826026d909a2cde0b02c8b763 (patch)
tree1457bbd62edb14e6810db39c0f6193d3b15ccbd2
parent6276b33d1980cc0010962e8ff649ca49ea4a6f71 (diff)
downloadprosody-4202df3e79ad611826026d909a2cde0b02c8b763.tar.gz
prosody-4202df3e79ad611826026d909a2cde0b02c8b763.zip
util.ip: Cache return values of all methods in one place
-rw-r--r--util/ip.lua6
1 files changed, 5 insertions, 1 deletions
diff --git a/util/ip.lua b/util/ip.lua
index 9dd6184f..ebeaf1c0 100644
--- a/util/ip.lua
+++ b/util/ip.lua
@@ -12,7 +12,11 @@ local ip_methods = {};
local ip_mt = {
__index = function (ip, key)
- return ip_methods[key](ip);
+ local method = ip_methods[key];
+ if not method then return nil; end
+ local ret = method(ip);
+ ip[key] = ret;
+ return ret;
end,
__tostring = function (ip) return ip.addr; end,
__eq = function (ipA, ipB) return ipA.addr == ipB.addr; end