mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
preallocating slices (#904)
* preallocated some slices when size is known * gofmt * gofmt
This commit is contained in:
parent
2f3c251b00
commit
24b8d2a315
@ -171,7 +171,7 @@ func (n *Network) Routes(ctx context.Context, req *pbNet.RoutesRequest, resp *pb
|
||||
return errors.InternalServerError("go.micro.network", "failed to list routes: %s", err)
|
||||
}
|
||||
|
||||
var respRoutes []*pbRtr.Route
|
||||
respRoutes := make([]*pbRtr.Route, 0, len(routes))
|
||||
for _, route := range routes {
|
||||
respRoute := &pbRtr.Route{
|
||||
Service: route.Service,
|
||||
|
@ -95,7 +95,7 @@ func toNodes(routes []router.Route) []string {
|
||||
}
|
||||
|
||||
func toSlice(r map[uint64]router.Route) []router.Route {
|
||||
var routes []router.Route
|
||||
routes := make([]router.Route, 0, len(r))
|
||||
for _, v := range r {
|
||||
routes = append(routes, v)
|
||||
}
|
||||
@ -224,7 +224,7 @@ func (p *Proxy) cacheRoutes(service string) ([]router.Route, error) {
|
||||
// refreshMetrics will refresh any metrics for our local cached routes.
|
||||
// we may not receive new watch events for these as they change.
|
||||
func (p *Proxy) refreshMetrics() {
|
||||
var services []string
|
||||
services := make([]string, 0, len(p.Routes))
|
||||
|
||||
// get a list of services to update
|
||||
p.RLock()
|
||||
|
@ -89,7 +89,7 @@ func (s *serviceRegistry) GetService(name string) ([]*registry.Service, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var services []*registry.Service
|
||||
services := make([]*registry.Service, 0, len(rsp.Services))
|
||||
for _, service := range rsp.Services {
|
||||
services = append(services, ToService(service))
|
||||
}
|
||||
@ -102,7 +102,7 @@ func (s *serviceRegistry) ListServices() ([]*registry.Service, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var services []*registry.Service
|
||||
services := make([]*registry.Service, 0, len(rsp.Services))
|
||||
for _, service := range rsp.Services {
|
||||
services = append(services, ToService(service))
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ func (w *workersKV) List() ([]*store.Record, error) {
|
||||
return nil, errors.New(messages)
|
||||
}
|
||||
|
||||
var keys []string
|
||||
keys := make([]string, 0, len(a.Result))
|
||||
|
||||
for _, r := range a.Result {
|
||||
keys = append(keys, r.Name)
|
||||
|
@ -32,7 +32,7 @@ func (e *ekv) Read(keys ...string) ([]*store.Record, error) {
|
||||
values = append(values, keyval.Kvs...)
|
||||
}
|
||||
|
||||
var records []*store.Record
|
||||
records := make([]*store.Record, 0, len(values))
|
||||
|
||||
for _, kv := range values {
|
||||
records = append(records, &store.Record{
|
||||
|
@ -1186,7 +1186,7 @@ func (t *tun) Links() []Link {
|
||||
t.RLock()
|
||||
defer t.RUnlock()
|
||||
|
||||
var links []Link
|
||||
links := make([]Link, 0, len(t.links))
|
||||
|
||||
for _, link := range t.links {
|
||||
links = append(links, link)
|
||||
|
Loading…
Reference in New Issue
Block a user