Skip to content

Commit 0f170b4

Browse files
authored
Use Set to spot duplicated log handler warnings. (#306)
Motivation: Feels like a better fit for the problem when a dictionary of bools. Modifications: Convert storage to set. Result: Fewer lines of code, less waste.
1 parent 2351723 commit 0f170b4

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Sources/Logging/Logging.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,17 +1347,13 @@ extension Logger.MetadataValue: ExpressibleByArrayLiteral {
13471347
/// Contains state to manage all kinds of "warn only once" warnings which the logging system may want to issue.
13481348
private final class WarnOnceBox {
13491349
private let lock: Lock = Lock()
1350-
private var warnOnceLogHandlerNotSupportedMetadataProviderPerType: [ObjectIdentifier: Bool] = [:]
1350+
private var warnOnceLogHandlerNotSupportedMetadataProviderPerType = Set<ObjectIdentifier>()
13511351

13521352
func warnOnceLogHandlerNotSupportedMetadataProvider<Handler: LogHandler>(type: Handler.Type) -> Bool {
13531353
self.lock.withLock {
13541354
let id = ObjectIdentifier(type)
1355-
if warnOnceLogHandlerNotSupportedMetadataProviderPerType[id] ?? false {
1356-
return false // don't warn, it was already warned about
1357-
} else {
1358-
warnOnceLogHandlerNotSupportedMetadataProviderPerType[id] = true
1359-
return true // warn about this handler type, it is the first time we encountered it
1360-
}
1355+
let (inserted, _) = warnOnceLogHandlerNotSupportedMetadataProviderPerType.insert(id)
1356+
return inserted // warn about this handler type, it is the first time we encountered it
13611357
}
13621358
}
13631359
}

0 commit comments

Comments
 (0)