mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 09:50:00 +08:00
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:
committed by
GitHub
parent
a2b98dbcf7
commit
130e1ba963
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user