# HG changeset patch # User Kim Alvefur # Date 1512091525 -3600 # Node ID ab9ddfb03d4d036afd4b257bf68fc0007eb727c2 # Parent 47195f035d2fc875a652b4974bf993dab185f85b util.ip: Cache return values of all methods in one place diff -r 47195f035d2f -r ab9ddfb03d4d util/ip.lua --- a/util/ip.lua Fri Dec 01 02:23:57 2017 +0100 +++ b/util/ip.lua Fri Dec 01 02:25:25 2017 +0100 @@ -12,7 +12,11 @@ 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