Move reflect.ValueOf out of product variable loop

Calling reflect.ValueOf for every variable for every module was
using ~3 seconds of CPU time on my AOSP builds.

Test: m checkbuild
Change-Id: Idf459ad8ddf5e07f6c0df0e58e2442aaa6ab3342
This commit is contained in:
Colin Cross 2021-01-20 11:27:32 -08:00
parent 324234bd00
commit 0cec312660

View file

@ -440,13 +440,15 @@ func VariableMutator(mctx BottomUpMutatorContext) {
variableValues := reflect.ValueOf(a.variableProperties).Elem().FieldByName("Product_variables")
productVariables := reflect.ValueOf(mctx.Config().productVariables)
for i := 0; i < variableValues.NumField(); i++ {
variableValue := variableValues.Field(i)
name := variableValues.Type().Field(i).Name
property := "product_variables." + proptools.PropertyNameForField(name)
// Check that the variable was set for the product
val := reflect.ValueOf(mctx.Config().productVariables).FieldByName(name)
val := productVariables.FieldByName(name)
if !val.IsValid() || val.Kind() != reflect.Ptr || val.IsNil() {
continue
}