terraform: deepcopy should not alloc when nil

This commit is contained in:
Armon Dadgar 2014-09-19 16:15:52 -07:00
parent 8e421caba1
commit 1d96373a54
1 changed files with 16 additions and 10 deletions

View File

@ -94,6 +94,9 @@ func (s *State) deepcopy() *State {
// prune is used to remove any resources that are no longer required
func (s *State) prune() {
if s == nil {
return
}
for _, mod := range s.Modules {
mod.prune()
}
@ -392,12 +395,14 @@ func (i *InstanceState) deepcopy() *InstanceState {
}
n := &InstanceState{
ID: i.ID,
Attributes: make(map[string]string, len(i.Attributes)),
Ephemeral: *i.Ephemeral.deepcopy(),
}
if i.Attributes != nil {
n.Attributes = make(map[string]string, len(i.Attributes))
for k, v := range i.Attributes {
n.Attributes[k] = v
}
}
return n
}
@ -489,12 +494,13 @@ func (e *EphemeralState) deepcopy() *EphemeralState {
if e == nil {
return nil
}
n := &EphemeralState{
ConnInfo: make(map[string]string, len(e.ConnInfo)),
}
n := &EphemeralState{}
if e.ConnInfo != nil {
n.ConnInfo = make(map[string]string, len(e.ConnInfo))
for k, v := range e.ConnInfo {
n.ConnInfo[k] = v
}
}
return n
}