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
diff --git a/android/variable.go b/android/variable.go
index 73be7a0..9b3ed17 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -440,13 +440,15 @@
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
}