Skip to content

Commit 3b8a6f6

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 3b8a6f6

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

pkg/apis/pipeline/v1/matrix_types.go

+7-12
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,26 @@ 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
}
7979

8080
// overwriteCombinations replaces any missing include params in the initial
8181
// matrix params combinations by overwriting the initial combinations with the
8282
// include combinations
83-
func (cs Combinations) overwriteCombinations(ics Combinations) Combinations {
83+
func (cs Combinations) overwriteCombinations(ics 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
}
91-
return cs
9295
}
9396

9497
// addNewCombinations creates a new combination for any include parameter
@@ -115,14 +118,6 @@ func (c Combination) contains(includeCombination Combination) bool {
115118
return true
116119
}
117120

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-
126121
// shouldAddNewCombination returns true if the include parameter name exists but the value is
127122
// missing from combinations
128123
func (cs Combinations) shouldAddNewCombination(includeCombination map[string]string) bool {

pkg/apis/pipeline/v1beta1/matrix_types.go

+7-15
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,23 @@ 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
}
7979

80-
// overwriteCombinations replaces any missing include params in the initial
81-
// matrix params combinations by overwriting the initial combinations with the
82-
// include combinations
83-
func (cs Combinations) overwriteCombinations(ics Combinations) Combinations {
80+
func (cs Combinations) overwriteCombinations(ics Combinations) {
8481
for _, paramCombination := range cs {
8582
for _, includeCombination := range ics {
8683
if paramCombination.contains(includeCombination) {
87-
includeCombination.overwrite(paramCombination)
84+
// overwrite the parameter name and value in existing combination
85+
// with the include combination
86+
for name, val := range includeCombination {
87+
paramCombination[name] = val
88+
}
8889
}
8990
}
9091
}
91-
return cs
9292
}
9393

9494
// addNewCombinations creates a new combination for any include parameter
@@ -115,14 +115,6 @@ func (c Combination) contains(includeCombination Combination) bool {
115115
return true
116116
}
117117

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-
126118
// shouldAddNewCombination returns true if the include parameter name exists but the value is
127119
// missing from combinations
128120
func (cs Combinations) shouldAddNewCombination(includeCombination map[string]string) bool {

0 commit comments

Comments
 (0)