Skip to content

Commit ed4f136

Browse files
author
Jason Yellick
committed
[FAB-2196] Improve subset efficiency
https://jira.hyperledger.org/browse/FAB-2196 Per feedback from @muralisr in https://gerrit.hyperledger.org/r/#/c/5771/ It makes more sense to check for set size before iterating to check subsetting. This CR implements that suggestion. Change-Id: I82cccb35ce8e4982d12d354baed3f9f8babea8d8 Signed-off-by: Jason Yellick <[email protected]>
1 parent c341fe5 commit ed4f136

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

common/configtx/compare.go

+12-27
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func subsetOfGroups(inner, outer map[string]*cb.ConfigGroup) bool {
8080
return true
8181
}
8282

83-
// If inner is not the empty set, then the outer empty set cannot be a superset of inner
84-
if len(outer) == 0 {
83+
// If inner has more elements than outer, it cannot be a subset
84+
if len(inner) > len(outer) {
8585
return false
8686
}
8787

@@ -101,8 +101,8 @@ func subsetOfPolicies(inner, outer map[string]*cb.ConfigPolicy) bool {
101101
return true
102102
}
103103

104-
// If inner is not the empty set, then the outer empty set cannot be a superset of inner
105-
if len(outer) == 0 {
104+
// If inner has more elements than outer, it cannot be a subset
105+
if len(inner) > len(outer) {
106106
return false
107107
}
108108

@@ -122,8 +122,8 @@ func subsetOfValues(inner, outer map[string]*cb.ConfigValue) bool {
122122
return true
123123
}
124124

125-
// If inner is not the empty set, then the outer empty set cannot be a superset of inner
126-
if len(outer) == 0 {
125+
// If inner has more elements than outer, it cannot be a subset
126+
if len(inner) > len(outer) {
127127
return false
128128
}
129129

@@ -143,27 +143,12 @@ func equalConfigGroup(lhs, rhs *cb.ConfigGroup) bool {
143143
return false
144144
}
145145

146-
if !subsetOfGroups(lhs.Groups, rhs.Groups) {
147-
return false
148-
}
149-
150-
if !subsetOfGroups(rhs.Groups, lhs.Groups) {
151-
return false
152-
}
153-
154-
if !subsetOfPolicies(lhs.Policies, rhs.Policies) {
155-
return false
156-
}
157-
158-
if !subsetOfPolicies(rhs.Policies, lhs.Policies) {
159-
return false
160-
}
161-
162-
if !subsetOfValues(lhs.Values, rhs.Values) {
163-
return false
164-
}
165-
166-
if !subsetOfValues(rhs.Values, lhs.Values) {
146+
if !subsetOfGroups(lhs.Groups, rhs.Groups) ||
147+
!subsetOfGroups(rhs.Groups, lhs.Groups) ||
148+
!subsetOfPolicies(lhs.Policies, rhs.Policies) ||
149+
!subsetOfPolicies(rhs.Policies, lhs.Policies) ||
150+
!subsetOfValues(lhs.Values, rhs.Values) ||
151+
!subsetOfValues(rhs.Values, lhs.Values) {
167152
return false
168153
}
169154

0 commit comments

Comments
 (0)