Skip to content

Commit 6593acf

Browse files
committed
Refactor Overwriting Combinations in Matrix
This commit refactors the overwriting combinations function within fanning out the Matrix to reduce the number of calls as requested by Priti in PR: tektoncd#6341.
1 parent 9ff6034 commit 6593acf

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

pkg/apis/pipeline/v1/matrix_types.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (m *Matrix) FanOut() []Params {
7272
for _, parameter := range m.Params {
7373
combinations = combinations.fanOutMatrixParams(parameter)
7474
}
75-
combinations = combinations.overwriteCombinations(includeCombinations)
75+
combinations.overwriteCombinations(includeCombinations)
7676
combinations = combinations.addNewCombinations(includeCombinations)
7777
return combinations.toParams()
7878
}
@@ -84,7 +84,11 @@ func (cs Combinations) overwriteCombinations(ics Combinations) Combinations {
8484
for _, paramCombination := range cs {
8585
for _, includeCombination := range ics {
8686
if paramCombination.contains(includeCombination) {
87-
includeCombination.overwrite(paramCombination)
87+
// overwrite the parameter name and value in existing combination
88+
// with the include combination
89+
for name, val := range includeCombination {
90+
paramCombination[name] = val
91+
}
8892
}
8993
}
9094
}
@@ -115,14 +119,6 @@ func (c Combination) contains(includeCombination Combination) bool {
115119
return true
116120
}
117121

118-
// overwrite the parameter name and value exists in combination with the include combination
119-
func (c Combination) overwrite(oldCombination Combination) Combination {
120-
for name, val := range c {
121-
oldCombination[name] = val
122-
}
123-
return oldCombination
124-
}
125-
126122
// shouldAddNewCombination returns true if the include parameter name exists but the value is
127123
// missing from combinations
128124
func (cs Combinations) shouldAddNewCombination(includeCombination map[string]string) bool {

pkg/apis/pipeline/v1beta1/matrix_types.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (m *Matrix) FanOut() []Params {
7272
for _, parameter := range m.Params {
7373
combinations = combinations.fanOutMatrixParams(parameter)
7474
}
75-
combinations = combinations.overwriteCombinations(includeCombinations)
75+
combinations.overwriteCombinations(includeCombinations)
7676
combinations = combinations.addNewCombinations(includeCombinations)
7777
return combinations.toParams()
7878
}
@@ -84,7 +84,11 @@ func (cs Combinations) overwriteCombinations(ics Combinations) Combinations {
8484
for _, paramCombination := range cs {
8585
for _, includeCombination := range ics {
8686
if paramCombination.contains(includeCombination) {
87-
includeCombination.overwrite(paramCombination)
87+
// overwrite the parameter name and value in existing combination
88+
// with the include combination
89+
for name, val := range includeCombination {
90+
paramCombination[name] = val
91+
}
8892
}
8993
}
9094
}
@@ -115,14 +119,6 @@ func (c Combination) contains(includeCombination Combination) bool {
115119
return true
116120
}
117121

118-
// overwrite the parameter name and value exists in combination with the include combination
119-
func (c Combination) overwrite(oldCombination Combination) Combination {
120-
for name, val := range c {
121-
oldCombination[name] = val
122-
}
123-
return oldCombination
124-
}
125-
126122
// shouldAddNewCombination returns true if the include parameter name exists but the value is
127123
// missing from combinations
128124
func (cs Combinations) shouldAddNewCombination(includeCombination map[string]string) bool {

0 commit comments

Comments
 (0)