Skip to content

Commit

Permalink
http_ng/headers: simplify capitalize method
Browse files Browse the repository at this point in the history
Avoid using regex. It's much more performant this way. Using Apicast in
echo mode, in a particular setup it went from ~3.5k rps to ~5k.
  • Loading branch information
davidor committed Nov 2, 2017
1 parent 695a3f7 commit 4efa022
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions apicast/src/resty/http_ng/headers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local getmetatable = getmetatable
local type = type
local lower = string.lower
local upper = string.upper
local sub = string.sub
local ngx_re = ngx.re

local normalize_exceptions = {
Expand All @@ -26,12 +27,8 @@ local headers_mt = {
end
}

local regex_first_letter = [[^\w]]
local upper_first_match = function(matches) return upper(matches[0]) end

local capitalize = function(string)
local str = ngx_re.sub(string, regex_first_letter, upper_first_match, 'jo')
return str
return upper(sub(string, 1, 1)) .. sub(string, 2)
end

local regex_parts = [[[^_-]+]]
Expand Down

0 comments on commit 4efa022

Please sign in to comment.