From 28770c01187e405d6bbcb27d5cb4d6adc537c370 Mon Sep 17 00:00:00 2001 From: Xiaochen Wang Date: Thu, 11 Jul 2024 14:40:04 +0800 Subject: [PATCH] perf(dns): reduce table creation --- kong/dns/utils.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kong/dns/utils.lua b/kong/dns/utils.lua index 3158c5ce945e..1eb8ec9d357e 100644 --- a/kong/dns/utils.lua +++ b/kong/dns/utils.lua @@ -8,6 +8,7 @@ local type = type local ipairs = ipairs local tonumber = tonumber local math_random = math.random +local table_clear = require("table.clear") local table_insert = table.insert local table_remove = table.remove @@ -257,7 +258,8 @@ do for _, answer in ipairs(answers) do if answer.priority < lowest_priority then lowest_priority = answer.priority - l = { answer } + table_clear(l) + l[1] = answer elseif answer.priority == lowest_priority then table_insert(l, answer)