Skip to content

Commit

Permalink
perf: replace string.sub with string.byte (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuruidong authored Oct 7, 2023
1 parent e14cbed commit f79bd0f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/resty/radixtree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ local empty_table = {}
local str_find = string.find
local str_lower = string.lower
local remove_tab = table.remove
local str_byte = string.byte
local ASTERISK = str_byte("*")


setmetatable(empty_table, {__newindex = function()
Expand Down Expand Up @@ -439,7 +441,7 @@ local function common_route_data(path, route, route_opts, global_opts)
route_opts.hosts = {}
for _, h in ipairs(hosts) do
local is_wildcard = false
if h and h:sub(1, 1) == '*' then
if h and str_byte(h) == ASTERISK then
is_wildcard = true
h = h:sub(2)
end
Expand All @@ -452,7 +454,7 @@ local function common_route_data(path, route, route_opts, global_opts)
elseif type(hosts) == "string" then
local is_wildcard = false
local host = str_lower(hosts)
if host:sub(1, 1) == '*' then
if str_byte(host) == ASTERISK then
is_wildcard = true
host = host:sub(2)
end
Expand Down

0 comments on commit f79bd0f

Please sign in to comment.