Merge pull request #16089 from wgliang/optimization-merge-slice

Optimization merge slice
This commit is contained in:
James Bardin 2017-10-02 16:40:13 -04:00 committed by GitHub
commit 08ac4f3a2e
4 changed files with 7 additions and 13 deletions

View File

@ -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
}

View File

@ -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)
}

View File

@ -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

View File

@ -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
}