Skip to content

Commit d0860a9

Browse files
committed
---
yaml --- r: 347775 b: refs/heads/master c: 160f5b3 h: refs/heads/master i: 347773: 65f355a 347771: 5b15942 347767: 3707717 347759: e91074a 347743: d83ca9b 347711: f2af98a 347647: fed6594
1 parent 9942773 commit d0860a9

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0b83965a447ad8f7e6bc98f2fbacd5491e9507a6
2+
refs/heads/master: 160f5b30a1b1b22d293686d04ffe4c4d404ca18e
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/stdlib/public/core/ClosedRange.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,12 @@ extension ClosedRange where Bound: Strideable, Bound.Stride : SignedInteger {
444444
extension ClosedRange {
445445
@inlinable
446446
public func overlaps(_ other: ClosedRange<Bound>) -> Bool {
447-
return self.contains(other.lowerBound) || other.contains(lowerBound)
447+
// Disjoint iff the other range is completely before or after our range.
448+
// Unlike a `Range`, a `ClosedRange` can *not* be empty, so no check for
449+
// that case is needed here.
450+
let isDisjoint = other.upperBound < self.lowerBound
451+
|| self.upperBound < other.lowerBound
452+
return !isDisjoint
448453
}
449454

450455
@inlinable

trunk/stdlib/public/core/Range.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,14 +943,26 @@ extension Range {
943943
/// common; otherwise, `false`.
944944
@inlinable
945945
public func overlaps(_ other: Range<Bound>) -> Bool {
946-
return (!other.isEmpty && self.contains(other.lowerBound))
947-
|| (!self.isEmpty && other.contains(self.lowerBound))
946+
// Disjoint iff the other range is completely before or after our range.
947+
// Additionally either `Range` (unlike a `ClosedRange`) could be empty, in
948+
// which case it is disjoint with everything as overlap is defined as having
949+
// an element in common.
950+
let isDisjoint = other.upperBound <= self.lowerBound
951+
|| self.upperBound <= other.lowerBound
952+
|| self.isEmpty || other.isEmpty
953+
return !isDisjoint
948954
}
949955

950956
@inlinable
951957
public func overlaps(_ other: ClosedRange<Bound>) -> Bool {
952-
return self.contains(other.lowerBound)
953-
|| (!self.isEmpty && other.contains(self.lowerBound))
958+
// Disjoint iff the other range is completely before or after our range.
959+
// Additionally the `Range` (unlike the `ClosedRange`) could be empty, in
960+
// which case it is disjoint with everything as overlap is defined as having
961+
// an element in common.
962+
let isDisjoint = other.upperBound < self.lowerBound
963+
|| self.upperBound <= other.lowerBound
964+
|| self.isEmpty
965+
return !isDisjoint
954966
}
955967
}
956968

0 commit comments

Comments
 (0)