1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-29 19:09:01 +00:00

Use local functions instead of anonymous functions for gsub (less GC overhead)

This commit is contained in:
dmiller
2020-11-30 23:22:06 +00:00
parent c8fdcd80b5
commit 86deb87187
5 changed files with 69 additions and 43 deletions

View File

@@ -445,6 +445,9 @@ end
-- Helpers
local function _hex_str (x)
return string.char(tonumber(x, 16))
end
--- Convert a MAC address string (like <code>"00:23:ae:5d:3b:10"</code>) to
-- a raw six-byte long.
-- @param str MAC address string.
@@ -453,9 +456,7 @@ function mactobin(str)
if not str then
return nil, "MAC was not specified."
end
return (str:gsub("(%x%x)[^%x]?", function (x)
return string.char(tonumber(x, 16))
end))
return (str:gsub("(%x%x)[^%x]?", _hex_str))
end
--- Generate the link-local IPv6 address from the MAC address.