From 4202df3e79ad611826026d909a2cde0b02c8b763 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 1 Dec 2017 02:25:25 +0100 Subject: util.ip: Cache return values of all methods in one place --- util/ip.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'util') 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 -- cgit v1.2.3