Move code out of the inner for loop as it only depend on the outer one

This commit is contained in:
alvaroloes 2015-12-31 14:03:36 +00:00
parent 04512eae0c
commit 54304668d7
1 changed files with 8 additions and 10 deletions

View File

@ -15,22 +15,20 @@ func (g *Generator) buildValueToNameMap(runs [][]Value, typeName string, runsThr
// At this moment, either "g.declareIndexAndNameVars()" or "g.declareNameVars()" has been called // At this moment, either "g.declareIndexAndNameVars()" or "g.declareNameVars()" has been called
g.Printf("\nvar _%sNameToValue_map = map[string]%s{\n", typeName, typeName) g.Printf("\nvar _%sNameToValue_map = map[string]%s{\n", typeName, typeName)
thereAreRuns := len(runs) > 1 && len(runs) <= runsThreshold thereAreRuns := len(runs) > 1 && len(runs) <= runsThreshold
n := 0 var n int
var runID string var runID string
for i, values := range runs { for i, values := range runs {
for _, value := range values { if thereAreRuns {
if thereAreRuns { runID = "_" + fmt.Sprintf("%d",i)
runID = "_" + fmt.Sprintf("%d",i) n = 0
} else { } else {
runID = "" runID = ""
} }
for _, value := range values {
g.Printf("\t_%s_name%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), &value) g.Printf("\t_%s_name%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), &value)
n += len(value.name) n += len(value.name)
} }
if thereAreRuns {
n = 0
}
} }
g.Printf("}\n\n") g.Printf("}\n\n")
g.Printf(stringValueToNameMap, typeName) g.Printf(stringValueToNameMap, typeName)