diff --git a/cmd/protoc-gen-go-http/http.go b/cmd/protoc-gen-go-http/http.go index 0d9458d82..5a363af31 100644 --- a/cmd/protoc-gen-go-http/http.go +++ b/cmd/protoc-gen-go-http/http.go @@ -236,8 +236,8 @@ func replacePath(name string, value string, path string) string { } func camelCaseVars(s string) string { - vars := make([]string, 0) subs := strings.Split(s, ".") + vars := make([]string, 0, len(subs)) for _, sub := range subs { vars = append(vars, camelCase(sub)) } diff --git a/contrib/config/etcd/config.go b/contrib/config/etcd/config.go index ea027c2a9..854b0a961 100644 --- a/contrib/config/etcd/config.go +++ b/contrib/config/etcd/config.go @@ -77,7 +77,7 @@ func (s *source) Load() ([]*config.KeyValue, error) { if err != nil { return nil, err } - kvs := make([]*config.KeyValue, 0) + kvs := make([]*config.KeyValue, 0, len(rsp.Kvs)) for _, item := range rsp.Kvs { k := string(item.Key) kvs = append(kvs, &config.KeyValue{ diff --git a/examples/blog/internal/data/article.go b/examples/blog/internal/data/article.go index c13cdf879..14fc67526 100644 --- a/examples/blog/internal/data/article.go +++ b/examples/blog/internal/data/article.go @@ -26,7 +26,7 @@ func (ar *articleRepo) ListArticle(ctx context.Context) ([]*biz.Article, error) if err != nil { return nil, err } - rv := make([]*biz.Article, 0) + rv := make([]*biz.Article, 0, len(ps)) for _, p := range ps { rv = append(rv, &biz.Article{ ID: p.ID,