Delay allocating variationMaps until populating them
Modules are created with a nil variantionMap, which avoids allocating an empty map if the module will never be split. Context.addVariationDependencies constructs a variationMap to compare against the variationMap of each variant, but constructed an empty variationMap if no variations were specified. A nil map is not the same as an empty map, so consistently use a nil map and create it when populating the first entry. Change-Id: I48b604659f9cdb23326b504a093cdfe5a3eb4f68
This commit is contained in:
parent
d03b59d03e
commit
9403b5a790
2 changed files with 12 additions and 2 deletions
11
context.go
11
context.go
|
@ -242,6 +242,9 @@ type Variation struct {
|
||||||
type variationMap map[string]string
|
type variationMap map[string]string
|
||||||
|
|
||||||
func (vm variationMap) clone() variationMap {
|
func (vm variationMap) clone() variationMap {
|
||||||
|
if vm == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
newVm := make(variationMap)
|
newVm := make(variationMap)
|
||||||
for k, v := range vm {
|
for k, v := range vm {
|
||||||
newVm[k] = v
|
newVm[k] = v
|
||||||
|
@ -1178,6 +1181,9 @@ func (c *Context) createVariations(origModule *moduleInfo, mutatorName string,
|
||||||
}
|
}
|
||||||
|
|
||||||
newVariant := origModule.variant.clone()
|
newVariant := origModule.variant.clone()
|
||||||
|
if newVariant == nil {
|
||||||
|
newVariant = make(variationMap)
|
||||||
|
}
|
||||||
newVariant[mutatorName] = variationName
|
newVariant[mutatorName] = variationName
|
||||||
|
|
||||||
m := *origModule
|
m := *origModule
|
||||||
|
@ -1521,10 +1527,11 @@ func (c *Context) addVariationDependency(module *moduleInfo, variations []Variat
|
||||||
var newVariant variationMap
|
var newVariant variationMap
|
||||||
if !far {
|
if !far {
|
||||||
newVariant = module.dependencyVariant.clone()
|
newVariant = module.dependencyVariant.clone()
|
||||||
} else {
|
|
||||||
newVariant = make(variationMap)
|
|
||||||
}
|
}
|
||||||
for _, v := range variations {
|
for _, v := range variations {
|
||||||
|
if newVariant == nil {
|
||||||
|
newVariant = make(variationMap)
|
||||||
|
}
|
||||||
newVariant[v.Mutator] = v.Variation
|
newVariant[v.Mutator] = v.Variation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -838,6 +838,9 @@ func (mctx *mutatorContext) createVariations(variationNames []string, local bool
|
||||||
for i, module := range modules {
|
for i, module := range modules {
|
||||||
ret = append(ret, module.logicModule)
|
ret = append(ret, module.logicModule)
|
||||||
if !local {
|
if !local {
|
||||||
|
if module.dependencyVariant == nil {
|
||||||
|
module.dependencyVariant = make(variationMap)
|
||||||
|
}
|
||||||
module.dependencyVariant[mctx.name] = variationNames[i]
|
module.dependencyVariant[mctx.name] = variationNames[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue