Skip to content

Commit 2a10400

Browse files
authored
Fix ResultSet Intersect method (#313)
1 parent 9ba5342 commit 2a10400

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pkg/authz/query/resultset.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,28 @@ func (rs *ResultSet) Union(other *ResultSet) *ResultSet {
108108
}
109109

110110
func (rs *ResultSet) Intersect(other *ResultSet) *ResultSet {
111-
resultSet := NewResultSet()
112-
var iter *ResultSetNode
111+
result := NewResultSet()
112+
var a, b *ResultSet
113113
if rs.Len() < other.Len() {
114-
iter = rs.List()
114+
a = rs
115+
b = other
115116
} else {
116-
iter = other.List()
117+
a = other
118+
b = rs
117119
}
118120

119-
for iter != nil {
120-
if other.Has(iter.ObjectType, iter.ObjectId, iter.Relation) {
121-
otherRes := other.Get(iter.ObjectType, iter.ObjectId, iter.Relation)
122-
if !otherRes.IsImplicit {
123-
resultSet.Add(otherRes.ObjectType, otherRes.ObjectId, otherRes.Relation, otherRes.Warrant, otherRes.IsImplicit)
121+
for iter := a.List(); iter != nil; iter = iter.Next() {
122+
if b.Has(iter.ObjectType, iter.ObjectId, iter.Relation) {
123+
bRes := b.Get(iter.ObjectType, iter.ObjectId, iter.Relation)
124+
if !bRes.IsImplicit {
125+
result.Add(bRes.ObjectType, bRes.ObjectId, bRes.Relation, bRes.Warrant, bRes.IsImplicit)
124126
} else {
125-
resultSet.Add(iter.ObjectType, iter.ObjectId, iter.Relation, iter.Warrant, iter.IsImplicit)
127+
result.Add(iter.ObjectType, iter.ObjectId, iter.Relation, iter.Warrant, iter.IsImplicit)
126128
}
127129
}
128-
129-
iter = iter.Next()
130130
}
131131

132-
return resultSet
132+
return result
133133
}
134134

135135
func (rs *ResultSet) String() string {

0 commit comments

Comments
 (0)