Skip to content

Commit f251a3c

Browse files
committed
Address comment
1 parent 4e602c4 commit f251a3c

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Sources/SparkConnect/CaseInsensitiveDictionary.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ public struct CaseInsensitiveDictionary: Sendable {
3636
return keyLowerCasedDictionary[key.lowercased()]
3737
}
3838
set {
39-
var newMap = originalDictionary.filter { $0.key.caseInsensitiveCompare(key) != .orderedSame }
40-
newMap[key] = newValue
41-
self.originalDictionary = newMap
42-
self.keyLowerCasedDictionary[key.lowercased()] = newValue
39+
let lowerKey = key.lowercased()
40+
if let newValue = newValue {
41+
keyLowerCasedDictionary[lowerKey] = newValue
42+
} else {
43+
keyLowerCasedDictionary.removeValue(forKey: lowerKey)
44+
}
45+
originalDictionary = originalDictionary.filter { $0.key.lowercased() != lowerKey }
46+
if let newValue = newValue {
47+
originalDictionary[key] = newValue
48+
}
4349
}
4450
}
4551

@@ -48,11 +54,7 @@ public struct CaseInsensitiveDictionary: Sendable {
4854
}
4955

5056
public func toStringDictionary() -> [String: String] {
51-
var dict = [String: String]()
52-
for (key, value) in originalDictionary {
53-
dict[key] = String(describing: value)
54-
}
55-
return dict
57+
return originalDictionary.mapValues { String(describing: $0) }
5658
}
5759

5860
public var count: Int {

0 commit comments

Comments
 (0)