perf: pre-allocate all known length arrays to avoid re-scaling (#5029)

Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
Ioannis Pinakoulakis
2025-08-08 19:03:25 +03:00
committed by GitHub
parent a2b98dbcf7
commit 130e1ba963
19 changed files with 29 additions and 28 deletions

View File

@@ -20,11 +20,11 @@ const (
var definedKeys = []string{bodyTagKey, formTagKey, pathTagKey, headerTagKey}
func (s Service) JoinPrefix() Service {
var groups []Group
groups := make([]Group, 0, len(s.Groups))
for _, g := range s.Groups {
prefix := strings.TrimSpace(g.GetAnnotation(RoutePrefixKey))
prefix = strings.ReplaceAll(prefix, `"`, "")
var routes []Route
routes := make([]Route, 0, len(g.Routes))
for _, r := range g.Routes {
r.Path = path.Join("/", prefix, r.Path)
routes = append(routes, r)

View File

@@ -66,7 +66,7 @@ func (t *Tags) Keys() []string {
if t == nil {
return []string{}
}
var keys []string
keys := make([]string, 0, len(t.tags))
for _, tag := range t.tags {
keys = append(keys, tag.Key)
}