Skip to content

Commit 01fa634

Browse files
Robert PietaRobert Pieta
Robert Pieta
authored and
Robert Pieta
committed
Improved performance of NSIndexSet.isEqual
1 parent 7773d64 commit 01fa634

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Foundation/NSIndexSet.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ open class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
115115
if _ranges.count != indexSet.rangeView.count {
116116
return false
117117
}
118-
118+
119119
// Iterate over indexes to compare each
120-
for (r1, r2) in zip(_ranges, indexSet.rangeView) {
120+
for (range, element) in zip(_ranges, indexSet.rangeView) {
121+
let elementLength = element.upperBound - element.lowerBound
122+
121123
// Return false if the ranges do not match
122-
if r1.location != r2.lowerBound || r1.length != r2.upperBound - r2.lowerBound {
124+
if range.location != element.lowerBound || range.length != elementLength {
123125
return false
124126
}
125127
}

0 commit comments

Comments
 (0)