@@ -608,18 +608,40 @@ SequenceTypeTests.test("Set<T>.contains/CustomImplementation/${dispatch}") {
608
608
609
609
% end
610
610
611
- SequenceTypeTests . test ( " Range<Element>.contains/WhereElementIsComparable/dispatch " ) {
612
- let start = 0
613
- let end = 10
614
- let range = Range ( start: MinimalComparableIndexValue ( start) , end: MinimalComparableIndexValue ( end) )
615
- let count = 20
611
+ SequenceTypeTests . test ( " Range<Element>.contains/WhereElementIsComparable/staticDispatch " ) {
612
+ let start = 10
613
+ let end = 20
614
+ let range : Range < MinimalComparableIndexValue > =
615
+ MinimalComparableIndexValue ( start) ..< MinimalComparableIndexValue ( end)
616
+ expectEqual (
617
+ 1 , MinimalComparableIndexValue . timesLessWasCalled. value)
618
+ let count = 30
616
619
for test in 0 ..< count {
617
620
expectEqual (
618
621
test >= start && test < end,
619
622
range. contains ( MinimalComparableIndexValue ( test) ) )
620
623
}
621
624
expectEqual (
622
- count * 2 , MinimalComparableIndexValue . timesLessWasCalled. value)
625
+ 51 , MinimalComparableIndexValue . timesLessWasCalled. value)
626
+ }
627
+
628
+ SequenceTypeTests . test ( " Range<Element>.contains/WhereElementIsComparable/dispatch " ) {
629
+ let start = 10
630
+ let end = 20
631
+ let range : Range < MinimalComparableIndexValue > =
632
+ MinimalComparableIndexValue ( start) ..< MinimalComparableIndexValue ( end)
633
+ expectEqual (
634
+ 1 , MinimalComparableIndexValue . timesLessWasCalled. value)
635
+ let count = 30
636
+ for test in 0 ..< count {
637
+ expectEqual (
638
+ test >= start && test < end,
639
+ LoggingCollection ( range) . contains ( MinimalComparableIndexValue ( test) ) )
640
+ }
641
+ // Dispatch through a protocol does not get the optimization because the
642
+ // custom contains method is not getting into the witness table.
643
+ expectEqual (
644
+ 1 , MinimalComparableIndexValue . timesLessWasCalled. value)
623
645
}
624
646
625
647
SequenceTypeTests . test ( " contains/Predicate " ) {
0 commit comments