Skip to content

Commit

Permalink
Improve performance by using copy instead of recompile
Browse files Browse the repository at this point in the history
* Copy regexp in session instead of recompile on every request.
  • Loading branch information
yookoala committed Feb 5, 2021
1 parent e5eda92 commit a512850
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ type FileSystemRouter struct {
// DOCUMENT_ROOT
//
func (fs *FileSystemRouter) Router() Middleware {
pathinfoRe := regexp.MustCompile(`^(.+\.php)(/?.+)$`)
return func(inner SessionHandler) SessionHandler {
return func(client Client, req *Request) (*ResponsePipe, error) {

Expand All @@ -207,8 +208,7 @@ func (fs *FileSystemRouter) Router() Middleware {
fastcgiScriptName := r.URL.Path

var fastcgiPathInfo string
pathinfoRe := regexp.MustCompile(`^(.+\.php)(/?.+)$`)
if matches := pathinfoRe.FindStringSubmatch(fastcgiScriptName); len(matches) > 0 {
if matches := pathinfoRe.Copy().FindStringSubmatch(fastcgiScriptName); len(matches) > 0 {
fastcgiScriptName, fastcgiPathInfo = matches[1], matches[2]
}

Expand Down

0 comments on commit a512850

Please sign in to comment.