Skip to content

Commit cd4b17e

Browse files
authored
Merge pull request #1 from ChrisBenua/swift-runtime-overhead-optimization
2 parents 760cae3 + 7c65a6d commit cd4b17e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Sources/ReerJSON/JSONDecoderImpl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ final class JSONDecoderImpl: Decoder {
168168
if type == Decimal.self {
169169
return try unboxDecimal(from: value, for: codingPathNode, additionalKey) as! T
170170
}
171-
if let dictType = type as? StringDecodableDictionary.Type {
171+
if !options.keyDecodingStrategy.isDefault, let dictType = type as? StringDecodableDictionary.Type {
172172
return try unboxDictionary(from: value, as: dictType, for: codingPathNode, additionalKey)
173173
}
174174

Sources/ReerJSON/Utilities.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ extension Dictionary : StringDecodableDictionary where Key == String, Value: Dec
127127
static var elementType: Decodable.Type { return Value.self }
128128
}
129129

130+
extension JSONDecoder.KeyDecodingStrategy {
131+
@inline(__always)
132+
var isDefault: Bool {
133+
switch self {
134+
case .useDefaultKeys:
135+
return true
136+
default:
137+
return false
138+
}
139+
}
140+
}
141+
130142
// This is a workaround for the lack of a "set value only if absent" function for Dictionary.
131143
extension Optional {
132144
mutating func _setIfNil(to value: Wrapped) {

0 commit comments

Comments
 (0)