Skip to content

Commit f79bd0f

Browse files
authored
perf: replace string.sub with string.byte (#135)
1 parent e14cbed commit f79bd0f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/resty/radixtree.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ local empty_table = {}
5555
local str_find = string.find
5656
local str_lower = string.lower
5757
local remove_tab = table.remove
58+
local str_byte = string.byte
59+
local ASTERISK = str_byte("*")
5860

5961

6062
setmetatable(empty_table, {__newindex = function()
@@ -439,7 +441,7 @@ local function common_route_data(path, route, route_opts, global_opts)
439441
route_opts.hosts = {}
440442
for _, h in ipairs(hosts) do
441443
local is_wildcard = false
442-
if h and h:sub(1, 1) == '*' then
444+
if h and str_byte(h) == ASTERISK then
443445
is_wildcard = true
444446
h = h:sub(2)
445447
end
@@ -452,7 +454,7 @@ local function common_route_data(path, route, route_opts, global_opts)
452454
elseif type(hosts) == "string" then
453455
local is_wildcard = false
454456
local host = str_lower(hosts)
455-
if host:sub(1, 1) == '*' then
457+
if str_byte(host) == ASTERISK then
456458
is_wildcard = true
457459
host = host:sub(2)
458460
end

0 commit comments

Comments
 (0)