aboutsummaryrefslogtreecommitdiffstats
path: root/util/ip.lua
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
commita4aa61fdb13a625e7bb9085aadc61a64b3bccd58 (patch)
tree1457bbd62edb14e6810db39c0f6193d3b15ccbd2 /util/ip.lua
parentb799561dca2799e88af234c78dd50394c233b3a2 (diff)
downloadprosody-a4aa61fdb13a625e7bb9085aadc61a64b3bccd58.tar.gz
prosody-a4aa61fdb13a625e7bb9085aadc61a64b3bccd58.zip
util.ip: Cache return values of all methods in one place
Diffstat (limited to 'util/ip.lua')
-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