Skip to content

Commit

Permalink
Optimize ResultSet.Intersect method (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkajla12 authored Mar 21, 2024
1 parent 79f8ec6 commit 9ba5342
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/authz/query/resultset.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ func (rs *ResultSet) Union(other *ResultSet) *ResultSet {

func (rs *ResultSet) Intersect(other *ResultSet) *ResultSet {
resultSet := NewResultSet()
for iter := rs.List(); iter != nil; iter = iter.Next() {
var iter *ResultSetNode
if rs.Len() < other.Len() {
iter = rs.List()
} else {
iter = other.List()
}

for iter != nil {
if other.Has(iter.ObjectType, iter.ObjectId, iter.Relation) {
otherRes := other.Get(iter.ObjectType, iter.ObjectId, iter.Relation)
if !otherRes.IsImplicit {
Expand All @@ -118,6 +125,8 @@ func (rs *ResultSet) Intersect(other *ResultSet) *ResultSet {
resultSet.Add(iter.ObjectType, iter.ObjectId, iter.Relation, iter.Warrant, iter.IsImplicit)
}
}

iter = iter.Next()
}

return resultSet
Expand Down

0 comments on commit 9ba5342

Please sign in to comment.