Skip to content

Commit

Permalink
Revert "style(router): remove ipairs and optimize router select (#1…
Browse files Browse the repository at this point in the history
…1273)"

This reverts commit 073d2fd.
  • Loading branch information
chronolaw authored and dndx committed Aug 10, 2023
1 parent f37487d commit f55614c
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions kong/router/atc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local type = type
local assert = assert
local setmetatable = setmetatable
local pairs = pairs
local ipairs = ipairs
local tonumber = tonumber


Expand Down Expand Up @@ -77,8 +78,8 @@ do
CACHED_SCHEMA = schema.new()

for typ, fields in pairs(FIELDS) do
for i = 1, #fields do
assert(CACHED_SCHEMA:add_field(fields[i], typ))
for _, v in ipairs(fields) do
assert(CACHED_SCHEMA:add_field(v, typ))
end
end

Expand Down Expand Up @@ -165,8 +166,8 @@ end


local function has_header_matching_field(fields)
for i = 1, #fields do
if is_http_headers_field(fields[i]) then
for _, field in ipairs(fields) do
if is_http_headers_field(field) then
return true
end
end
Expand Down Expand Up @@ -224,7 +225,6 @@ local function new_from_scratch(routes, get_exp_and_priority)
routes = routes_t,
services = services_t,
fields = fields,
fields_n = #fields,
match_headers = match_headers,
updated_at = new_updated_at,
rebuilding = false,
Expand Down Expand Up @@ -312,7 +312,6 @@ local function new_from_previous(routes, get_exp_and_priority, old_router)
local fields = inst:get_fields()

old_router.fields = fields
old_router.fields_n = #fields
old_router.match_headers = has_header_matching_field(fields)
old_router.updated_at = new_updated_at
old_router.rebuilding = false
Expand Down Expand Up @@ -403,9 +402,7 @@ function _M:select(req_method, req_uri, req_host, req_scheme,

local host, port = split_host_port(req_host)

for i = 1, self.fields_n do
local field = self.fields[i]

for _, field in ipairs(self.fields) do
if field == "http.method" then
assert(c:add_value(field, req_method))

Expand Down Expand Up @@ -445,8 +442,8 @@ function _M:select(req_method, req_uri, req_host, req_scheme,
end

else
for idx = 1, #v do
local res, err = c:add_value(field, v[idx]:lower())
for _, v in ipairs(v) do
local res, err = c:add_value(field, v:lower())
if not res then
return nil, err
end
Expand Down Expand Up @@ -512,8 +509,8 @@ do
local name = name:gsub("-", "_"):lower()

if type(value) == "table" then
for i = 1, #value do
value[i] = value[i]:lower()
for i, v in ipairs(value) do
value[i] = v:lower()
end
tb_sort(value)
value = tb_concat(value, ", ")
Expand Down Expand Up @@ -613,9 +610,7 @@ function _M:select(_, _, _, scheme,

local c = context.new(self.schema)

for i = 1, self.fields_n do
local field = self.fields[i]

for _, field in ipairs(self.fields) do
if field == "net.protocol" then
assert(c:add_value(field, scheme))

Expand Down

1 comment on commit f55614c

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:f55614cc59b4d921306b8234cb7a6ad3163d27d0
Artifacts available https://github.com/Kong/kong/actions/runs/5817644120

Please sign in to comment.