Skip to content

Commit 1f567d0

Browse files
committed
Add a comment about using Locale.Components.icuIdentifier as the cache key
1 parent f99e2de commit 1f567d0

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

Sources/FoundationEssentials/Locale/Locale+Components.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ extension Locale {
8787
}
8888

8989
// Returns an ICU-style identifier like "de_DE@calendar=gregorian"
90+
// Must include every component stored by a `Locale.Components`, and be kept in sync with `init(identifier:)`.
9091
package var icuIdentifier: String {
9192

9293
var keywords = [(ICULegacyKey, String)]()

Sources/FoundationEssentials/Locale/Locale_Cache.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct LocaleCache : Sendable, ~Copyable {
4545
}
4646

4747
private var cachedFixedLocales: [String : any _LocaleProtocol] = [:]
48-
private var cachedFixedComponentsLocales: [String : any _LocaleProtocol] = [:]
48+
private var cachedFixedComponentsLocales: [String /*ICU identifier*/: any _LocaleProtocol] = [:]
4949

5050
#if FOUNDATION_FRAMEWORK
5151
private var cachedFixedIdentifierToNSLocales: [String : _NSSwiftLocale] = [:]
@@ -99,13 +99,9 @@ struct LocaleCache : Sendable, ~Copyable {
9999

100100
#endif // FOUNDATION_FRAMEWORK
101101

102-
func fixedComponents(_ comps: String) -> (any _LocaleProtocol)? {
103-
cachedFixedComponentsLocales[comps]
104-
}
105-
106102
mutating func fixedComponentsWithCache(_ comps: Locale.Components) -> any _LocaleProtocol {
107103
let identifier = comps.icuIdentifier
108-
if let l = fixedComponents(identifier) {
104+
if let l = cachedFixedComponentsLocales[identifier] {
109105
return l
110106
} else {
111107
let new = _localeICUClass().init(components: comps)

0 commit comments

Comments
 (0)