@@ -331,7 +331,7 @@ extension Calendar {
331331 let validates = matchingComponents. _validate ( for: calendar)
332332 finished = !validates
333333
334- self . usesFastPath = validates && matchingPolicy == . nextTime && repeatedTimePolicy == . first && calendar. _supportsNextDateFastPath ( for: matchingComponents)
334+ self . usesFastPath = validates && matchingPolicy == . nextTime && repeatedTimePolicy == . first && calendar. _supportsNextDateFastPath ( for: matchingComponents. _populatedComponentSet )
335335 }
336336
337337 mutating func next( ) -> Element ? {
@@ -536,11 +536,12 @@ extension Calendar {
536536 inSearchingDate searchingDate: Date ,
537537 previouslyReturnedMatchDate: Date ? ) throws -> SearchStepResult {
538538
539- // Fast-path: ask the calendar directly. Returns nil for unrecognized patterns.
540- if _supportsNextDateFastPath ( for: matchingComponents) && matchingPolicy == . nextTime && repeatedTimePolicy == . first {
539+ // Fast-path: ask the calendar directly.
540+ if _supportsNextDateFastPath ( for: matchingComponents. _populatedComponentSet ) && matchingPolicy == . nextTime && repeatedTimePolicy == . first {
541541 if let fast = _calendarNextDate ( after: searchingDate, matching: matchingComponents, direction: direction) {
542542 return SearchStepResult ( result: ( fast, true ) , newSearchDate: fast)
543543 }
544+ return SearchStepResult ( result: nil , newSearchDate: searchingDate)
544545 }
545546
546547 // Step A: Call helper method that does the searching
@@ -1659,12 +1660,14 @@ extension Calendar {
16591660 if month != dateMonth {
16601661 // Fast-path: advance to target month directly.
16611662 if !isLeapMonthDesired || !strictMatching {
1662- var minimal = DateComponents ( )
1663- minimal. month = month
1664- minimal. isLeapMonth = components. isLeapMonth
1665- if let fast = _calendarNextDate ( after: result, matching: minimal, direction: direction) {
1666- result = fast
1667- dateMonth = month
1663+ if _supportsNextDateFastPath ( for: [ . month] ) {
1664+ var minimal = DateComponents ( )
1665+ minimal. month = month
1666+ minimal. isLeapMonth = components. isLeapMonth
1667+ if let fast = _calendarNextDate ( after: result, matching: minimal, direction: direction) {
1668+ result = fast
1669+ dateMonth = month
1670+ }
16681671 }
16691672 }
16701673 if month != dateMonth {
@@ -1761,8 +1764,8 @@ extension Calendar {
17611764 if components. month == nil , components. weekday != nil {
17621765 var enriched = components
17631766 enriched. month = component ( . month, from: startingAt)
1764- if let fast = _calendarNextDate ( after : startingAt , matching : enriched, direction : direction ) {
1765- return fast
1767+ if _supportsNextDateFastPath ( for : enriched. _populatedComponentSet ) {
1768+ return _calendarNextDate ( after : startingAt , matching : enriched , direction : direction )
17661769 }
17671770 }
17681771
@@ -1856,8 +1859,8 @@ extension Calendar {
18561859 }
18571860
18581861 // Fast-path: ask the calendar directly.
1859- if let fast = _calendarNextDate ( after : startingAt , matching : components, direction : direction ) {
1860- return fast
1862+ if _supportsNextDateFastPath ( for : components. _populatedComponentSet ) {
1863+ return _calendarNextDate ( after : startingAt , matching : components , direction : direction )
18611864 }
18621865
18631866 // After this point, result is at least startDate
@@ -1967,10 +1970,10 @@ extension Calendar {
19671970 }
19681971
19691972 // Fast-path: use minimal {weekday}-only components.
1970- var minimal = DateComponents ( )
1971- minimal. weekday = weekday
1972- if let fast = _calendarNextDate ( after : startingAt , matching : minimal, direction : direction ) {
1973- return fast
1973+ if _supportsNextDateFastPath ( for : [ . weekday ] ) {
1974+ var minimal = DateComponents ( )
1975+ minimal. weekday = weekday
1976+ return _calendarNextDate ( after : startingAt , matching : minimal , direction : direction )
19741977 }
19751978
19761979 // After this point, result is at least startDate
0 commit comments