Changeset

8436:ab9ddfb03d4d

util.ip: Cache return values of all methods in one place
author Kim Alvefur <zash@zash.se>
date Fri, 01 Dec 2017 02:25:25 +0100
parents 8435:47195f035d2f
children 8437:021129f7b0a3
files util/ip.lua
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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