From 383b0c176c053cb70ef05cbc4e73bcd420c495e7 Mon Sep 17 00:00:00 2001 From: Wang Guoliang Date: Wed, 13 Sep 2017 20:58:14 +0800 Subject: [PATCH 1/2] optimization:use bytes.Equal instead of bytes.Compare --- communicator/ssh/communicator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/communicator/ssh/communicator_test.go b/communicator/ssh/communicator_test.go index 3f9d4f883..b2344fa55 100644 --- a/communicator/ssh/communicator_test.go +++ b/communicator/ssh/communicator_test.go @@ -381,7 +381,7 @@ func acceptPublicKey(keystr string) func(ssh.ConnMetadata, ssh.PublicKey) (*ssh. panic(fmt.Errorf("error parsing key: %s", err)) } return func(_ ssh.ConnMetadata, inkey ssh.PublicKey) (*ssh.Permissions, error) { - if bytes.Compare(inkey.Marshal(), goodkey.Marshal()) == 0 { + if bytes.Equal(inkey.Marshal(), goodkey.Marshal()) { return nil, nil } From 9a97c348f01c6b03f63afbc7d15761ac90557263 Mon Sep 17 00:00:00 2001 From: Wang Guoliang Date: Wed, 13 Sep 2017 21:04:55 +0800 Subject: [PATCH 2/2] optimization:Merge slices --- config/interpolate_walk.go | 4 +--- config/merge.go | 8 ++------ terraform/resource_address.go | 6 +++--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/config/interpolate_walk.go b/config/interpolate_walk.go index ead3d102e..66a677d5d 100644 --- a/config/interpolate_walk.go +++ b/config/interpolate_walk.go @@ -271,9 +271,7 @@ func (w *interpolationWalker) splitSlice() { result = append(result, val.Value) } case []interface{}: - for _, element := range val { - result = append(result, element) - } + result = append(result, val...) default: result = append(result, v) } diff --git a/config/merge.go b/config/merge.go index 23798d652..55fc864f7 100644 --- a/config/merge.go +++ b/config/merge.go @@ -144,12 +144,8 @@ func Merge(c1, c2 *Config) (*Config, error) { // Explicit length check above because we want c.Locals to remain // nil if the result would be empty. c.Locals = make([]*Local, 0, len(c1.Locals)+len(c2.Locals)) - for _, v := range c1.Locals { - c.Locals = append(c.Locals, v) - } - for _, v := range c2.Locals { - c.Locals = append(c.Locals, v) - } + c.Locals = append(c.Locals, c1.Locals...) + c.Locals = append(c.Locals, c2.Locals...) } return c, nil diff --git a/terraform/resource_address.go b/terraform/resource_address.go index 353725844..a64f5d846 100644 --- a/terraform/resource_address.go +++ b/terraform/resource_address.go @@ -42,9 +42,9 @@ func (r *ResourceAddress) Copy() *ResourceAddress { Type: r.Type, Mode: r.Mode, } - for _, p := range r.Path { - n.Path = append(n.Path, p) - } + + n.Path = append(n.Path, r.Path...) + return n }