Skip to content

Commit

Permalink
style(pdk/log): simplify buffer:put() with vararg-style (#13200)
Browse files Browse the repository at this point in the history
Using varags-style for `string.buffer:put()` will make the code easy to read.
  • Loading branch information
chronolaw authored Jun 26, 2024
1 parent 56d42be commit 324023e
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions kong/pdk/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,29 +152,29 @@ local serializers = {
end,

[2] = function(buf, sep, to_string, ...)
buf:put(to_string((select(1, ...)))):put(sep)
:put(to_string((select(2, ...))))
buf:put(to_string((select(1, ...))), sep,
to_string((select(2, ...))))
end,

[3] = function(buf, sep, to_string, ...)
buf:put(to_string((select(1, ...)))):put(sep)
:put(to_string((select(2, ...)))):put(sep)
:put(to_string((select(3, ...))))
buf:put(to_string((select(1, ...))), sep,
to_string((select(2, ...))), sep,
to_string((select(3, ...))))
end,

[4] = function(buf, sep, to_string, ...)
buf:put(to_string((select(1, ...)))):put(sep)
:put(to_string((select(2, ...)))):put(sep)
:put(to_string((select(3, ...)))):put(sep)
:put(to_string((select(4, ...))))
buf:put(to_string((select(1, ...))), sep,
to_string((select(2, ...))), sep,
to_string((select(3, ...))), sep,
to_string((select(4, ...))))
end,

[5] = function(buf, sep, to_string, ...)
buf:put(to_string((select(1, ...)))):put(sep)
:put(to_string((select(2, ...)))):put(sep)
:put(to_string((select(3, ...)))):put(sep)
:put(to_string((select(4, ...)))):put(sep)
:put(to_string((select(5, ...))))
buf:put(to_string((select(1, ...))), sep,
to_string((select(2, ...))), sep,
to_string((select(3, ...))), sep,
to_string((select(4, ...))), sep,
to_string((select(5, ...))))
end,
}

Expand Down Expand Up @@ -334,7 +334,7 @@ local function gen_log_func(lvl_const, imm_buf, to_string, stack_level, sep)

else
for i = 1, n - 1 do
variadic_buf:put(to_string((select(i, ...)))):put(sep or "")
variadic_buf:put(to_string((select(i, ...))), sep or "")
end
variadic_buf:put(to_string((select(n, ...))))
end
Expand Down

1 comment on commit 324023e

@github-actions
Copy link
Contributor

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:324023e79b3d0f296accb29eb560027b0ea860de
Artifacts available https://github.com/Kong/kong/actions/runs/9674298908

Please sign in to comment.