1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-27 01:49:03 +00:00

Memoize lpeg patterns for keywords in script spec/rules

This commit is contained in:
dmiller
2022-09-08 18:14:52 +00:00
parent 3cfe60c3ed
commit 2f6885f273

View File

@@ -278,9 +278,14 @@ local function host_copy(t)
end
-- Return a pattern which matches a "keyword" literal, case insensitive.
local memo_K = {}
local function K (a)
local insensitize = Cf((P(1) / function (a) return S(lower(a)..upper(a)) end)^1, function (a, b) return a * b end);
return assert(insensitize:match(a)) * #(V "space" + S"()," + P(-1)); -- "keyword" token
local kw = memo_K[a]
if not kw then
kw = U.caseless(a) * #(V "space" + S"()," + P(-1))
memo_K[a] = kw
end
return kw
end
local REQUIRE_ERROR = {};