@@ -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 ? {
@@ -537,7 +537,7 @@ extension Calendar {
537537 previouslyReturnedMatchDate: Date ? ) throws -> SearchStepResult {
538538
539539 // Fast-path: ask the calendar directly. Returns nil for unrecognized patterns.
540- if _supportsNextDateFastPath ( for: matchingComponents) && matchingPolicy == . nextTime && repeatedTimePolicy == . first {
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 }
@@ -1659,12 +1659,14 @@ extension Calendar {
16591659 if month != dateMonth {
16601660 // Fast-path: advance to target month directly.
16611661 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
1662+ if _supportsNextDateFastPath ( for: [ . month] ) {
1663+ var minimal = DateComponents ( )
1664+ minimal. month = month
1665+ minimal. isLeapMonth = components. isLeapMonth
1666+ if let fast = _calendarNextDate ( after: result, matching: minimal, direction: direction) {
1667+ result = fast
1668+ dateMonth = month
1669+ }
16681670 }
16691671 }
16701672 if month != dateMonth {
@@ -1761,8 +1763,8 @@ extension Calendar {
17611763 if components. month == nil , components. weekday != nil {
17621764 var enriched = components
17631765 enriched. month = component ( . month, from: startingAt)
1764- if let fast = _calendarNextDate ( after : startingAt , matching : enriched, direction : direction ) {
1765- return fast
1766+ if _supportsNextDateFastPath ( for : enriched. _populatedComponentSet ) {
1767+ return _calendarNextDate ( after : startingAt , matching : enriched , direction : direction )
17661768 }
17671769 }
17681770
@@ -1856,8 +1858,8 @@ extension Calendar {
18561858 }
18571859
18581860 // Fast-path: ask the calendar directly.
1859- if let fast = _calendarNextDate ( after : startingAt , matching : components, direction : direction ) {
1860- return fast
1861+ if _supportsNextDateFastPath ( for : components. _populatedComponentSet ) {
1862+ return _calendarNextDate ( after : startingAt , matching : components , direction : direction )
18611863 }
18621864
18631865 // After this point, result is at least startDate
@@ -1967,10 +1969,10 @@ extension Calendar {
19671969 }
19681970
19691971 // 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
1972+ if _supportsNextDateFastPath ( for : [ . weekday ] ) {
1973+ var minimal = DateComponents ( )
1974+ minimal. weekday = weekday
1975+ return _calendarNextDate ( after : startingAt , matching : minimal , direction : direction )
19741976 }
19751977
19761978 // After this point, result is at least startDate
0 commit comments