From cd282219c21e96492614b393407ee25841f57b58 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 Jun 2018 17:37:06 +0200 Subject: Backed out changeset eae606b9266c: Used a lot of memory --- net/dns.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'net') diff --git a/net/dns.lua b/net/dns.lua index 0d2cce01..8a7d4e7a 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -86,10 +86,9 @@ local function highbyte(i) -- - - - - - - - - - - - - - - - - - - highbyte end -local function augment (t, prefix) -- - - - - - - - - - - - - - - - - augment +local function augment (t) -- - - - - - - - - - - - - - - - - - - - augment local a = {}; - for i = 1, 0xffff do - local s = t[i] or ("%s%d"):format(prefix, i); + for i,s in pairs(t) do a[i] = s; a[s] = s; a[string.lower(s)] = s; @@ -120,8 +119,8 @@ dns.types = { dns.classes = { 'IN', 'CS', 'CH', 'HS', [255] = '*' }; -dns.type = augment (dns.types, "TYPE"); -dns.class = augment (dns.classes, "CLASS"); +dns.type = augment (dns.types); +dns.class = augment (dns.classes); dns.typecode = encode (dns.types); dns.classcode = encode (dns.classes); -- cgit v1.2.3 From 5788d3bc5349809fa94420b7cd3a04e5f7df37b2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 Jun 2018 17:45:49 +0200 Subject: net.dns: Lazily generate unknown RR type names --- net/dns.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'net') diff --git a/net/dns.lua b/net/dns.lua index 8a7d4e7a..563c81a6 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -86,13 +86,22 @@ local function highbyte(i) -- - - - - - - - - - - - - - - - - - - highbyte end -local function augment (t) -- - - - - - - - - - - - - - - - - - - - augment +local function augment (t, prefix) -- - - - - - - - - - - - - - - - - augment local a = {}; for i,s in pairs(t) do a[i] = s; a[s] = s; a[string.lower(s)] = s; end + setmetatable(a, { + __index = function (_, i) + if type(i) == "number" then + return ("%s%d"):format(prefix, i); + elseif type(i) == "string" then + return i:upper(); + end + end; + }) return a; end @@ -119,8 +128,8 @@ dns.types = { dns.classes = { 'IN', 'CS', 'CH', 'HS', [255] = '*' }; -dns.type = augment (dns.types); -dns.class = augment (dns.classes); +dns.type = augment (dns.types, "TYPE"); +dns.class = augment (dns.classes, "CLASS"); dns.typecode = encode (dns.types); dns.classcode = encode (dns.classes); -- cgit v1.2.3