Skip to content
Myr

perf(tree): optimize path parsing using strings.Count (#4246)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Name · committed by GitHub · parent 52f70cf · Browse files · 1 file+4 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: 1911860538 <alxps1911@gmail.com>

Diff stats

1 file+4 added−14 removed

  • other:+4 added−14 removed

1 file+4 added−14 removed

modified:tree.go+4 added-14 removed
3 unmodified lines
45package gin67import (8 "bytes"8 "net/url"9 "strings"10 "unicode"11 "unicode/utf8"1213 "github.com/gin-gonic/gin/internal/bytesconv"14)1517var (18 strColon = []byte(":")19 strStar = []byte("*")20 strSlash = []byte("/")21)2216// Param is a single URL parameter, consisting of a key and a value.17type Param struct {18 Key string19 Value string
57 unmodified lines
77 }78}7980func countParams(path string) uint16 {88 var n uint1689 s := bytesconv.StringToBytes(path)90 n += uint16(bytes.Count(s, strColon))91 n += uint16(bytes.Count(s, strStar))92 return n81 colons := strings.Count(path, ":")82 stars := strings.Count(path, "*")83 return uint16(colons + stars)84}8586func countSections(path string) uint16 {96 s := bytesconv.StringToBytes(path)97 return uint16(bytes.Count(s, strSlash))87 return uint16(strings.Count(path, "/"))88}8990type nodeType uint891
799 unmodified lines