File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments