@@ -17,6 +17,7 @@ import struct Foundation.Decimal
1717
1818public extension JSON {
1919 /// Returns `true` iff the receiver is `.null`.
20+ @inlinable
2021 var isNull : Bool {
2122 switch self {
2223 case . null: return true
@@ -25,6 +26,7 @@ public extension JSON {
2526 }
2627
2728 /// Returns `true` iff the receiver is `.bool`.
29+ @inlinable
2830 var isBool : Bool {
2931 switch self {
3032 case . bool: return true
@@ -33,6 +35,7 @@ public extension JSON {
3335 }
3436
3537 /// Returns `true` iff the receiver is `.string`.
38+ @inlinable
3639 var isString : Bool {
3740 switch self {
3841 case . string: return true
@@ -41,6 +44,7 @@ public extension JSON {
4144 }
4245
4346 /// Returns `true` iff the receiver is `.int64`.
47+ @inlinable
4448 var isInt64 : Bool {
4549 switch self {
4650 case . int64: return true
@@ -49,6 +53,7 @@ public extension JSON {
4953 }
5054
5155 /// Returns `true` iff the receiver is `.double`.
56+ @inlinable
5257 var isDouble : Bool {
5358 switch self {
5459 case . double: return true
@@ -57,6 +62,7 @@ public extension JSON {
5762 }
5863
5964 /// Returns `true` iff the receiver is a `.decimal`.
65+ @inlinable
6066 var isDecimal : Bool {
6167 switch self {
6268 case . decimal: return true
@@ -65,6 +71,7 @@ public extension JSON {
6571 }
6672
6773 /// Returns `true` iff the receiver is `.int64`, `.double`, or `.decimal`.
74+ @inlinable
6875 var isNumber : Bool {
6976 switch self {
7077 case . int64, . double, . decimal: return true
@@ -73,6 +80,7 @@ public extension JSON {
7380 }
7481
7582 /// Returns `true` iff the receiver is `.object`.
83+ @inlinable
7684 var isObject : Bool {
7785 switch self {
7886 case . object: return true
@@ -81,6 +89,7 @@ public extension JSON {
8189 }
8290
8391 /// Returns `true` iff the receiver is `.array`.
92+ @inlinable
8493 var isArray : Bool {
8594 switch self {
8695 case . array: return true
@@ -94,6 +103,7 @@ public extension JSON {
94103 ///
95104 /// When setting, replaces the receiver with the given boolean value, or with
96105 /// null if the value is `nil`.
106+ @inlinable
97107 var bool : Bool ? {
98108 get {
99109 switch self {
@@ -110,6 +120,7 @@ public extension JSON {
110120 ///
111121 /// When setting, replaces the receiver with the given string value, or with
112122 /// null if the value is `nil`.
123+ @inlinable
113124 var string : String ? {
114125 get {
115126 switch self {
@@ -129,6 +140,7 @@ public extension JSON {
129140 ///
130141 /// When setting, replaces the receiver with the given integral value, or with
131142 /// null if the value is `nil`.
143+ @inlinable
132144 var int64 : Int64 ? {
133145 get {
134146 switch self {
@@ -150,6 +162,7 @@ public extension JSON {
150162 ///
151163 /// When setting, replaces the receiver with the given integral value, or with
152164 /// null if the value is `nil`.
165+ @inlinable
153166 var int : Int ? {
154167 get {
155168 guard let value = self . int64 else { return nil }
@@ -167,6 +180,7 @@ public extension JSON {
167180 ///
168181 /// When setting, replaces the receiver with the given double value, or with
169182 /// null if the value is `nil`.
183+ @inlinable
170184 var double : Double ? {
171185 get {
172186 switch self {
@@ -187,6 +201,7 @@ public extension JSON {
187201 ///
188202 /// When setting, replaces the receiver with the given object value, or with
189203 /// null if the value is `nil`.
204+ @inlinable
190205 var object : JSONObject ? {
191206 get {
192207 switch self {
@@ -203,6 +218,7 @@ public extension JSON {
203218 ///
204219 /// When setting, replaces the receiver with the given array value, or with
205220 /// null if the value is `nil`.
221+ @inlinable
206222 var array : JSONArray ? {
207223 get {
208224 switch self {
@@ -219,6 +235,7 @@ public extension JSON {
219235public extension JSON {
220236 /// Returns the string value if the receiver is `.string`, coerces the value to a string if
221237 /// the receiver is `.bool`, `.null`, `.int64`, `.double`, or `.decimal, or otherwise returns `nil`.
238+ @inlinable
222239 var asString : String ? {
223240 return try ? toString ( )
224241 }
@@ -230,6 +247,7 @@ public extension JSON {
230247 /// in 64 bits, `nil` is returned.
231248 /// If the receiver is `.string`, it must parse fully as an integral or floating-point number.
232249 /// If it parses as a floating-point number, it is truncated. If it does not fit in 64 bits, `nil` is returned.
250+ @inlinable
233251 var asInt64 : Int64 ? {
234252 return try ? toInt64 ( )
235253 }
@@ -241,13 +259,15 @@ public extension JSON {
241259 /// in an `Int`, `nil` is returned.
242260 /// If the receiver is `.string`, it must parse fully as an integral or floating-point number.
243261 /// If it parses as a floating-point number, it is truncated. If it does not fit in an `Int`, `nil` is returned.
262+ @inlinable
244263 var asInt : Int ? {
245264 return try ? toInt ( )
246265 }
247266
248267 /// Returns the double value if the receiver is `.int64`, `.double`, or `.decimal`, coerces the value
249268 /// if the receiver is `.string`, otherwise returns `nil`.
250269 /// If the receiver is `.string`, it must parse fully as a floating-point number.
270+ @inlinable
251271 var asDouble : Double ? {
252272 return try ? toDouble ( )
253273 }
@@ -256,19 +276,22 @@ public extension JSON {
256276public extension JSON {
257277 /// If the receiver is `.object`, returns the result of subscripting the object.
258278 /// Otherwise, returns `nil`.
279+ @inlinable
259280 subscript( key: String ) -> JSON ? {
260281 return self . object ? [ key]
261282 }
262283
263284 /// If the receiver is `.array` and the index is in range of the array, returns the result of subscripting the array.
264285 /// Otherwise returns `nil`.
286+ @inlinable
265287 subscript( index: Int ) -> JSON ? {
266288 guard let ary = self . array else { return nil }
267289 guard index >= ary. startIndex && index < ary. endIndex else { return nil }
268290 return ary [ index]
269291 }
270292}
271293
294+ @usableFromInline
272295internal func convertDoubleToInt64( _ d: Double ) -> Int64 ? {
273296 // Int64(Double(Int64.max)) asserts because it interprets it as out of bounds.
274297 // Int64(Double(Int64.min)) works just fine.
@@ -278,6 +301,7 @@ internal func convertDoubleToInt64(_ d: Double) -> Int64? {
278301 return Int64 ( d)
279302}
280303
304+ @usableFromInline
281305internal func convertDecimalToInt64( _ d: Decimal ) -> Int64 ? {
282306 if d > Int64 . maxDecimal || d < Int64 . minDecimal {
283307 return nil
@@ -286,6 +310,7 @@ internal func convertDecimalToInt64(_ d: Decimal) -> Int64? {
286310 return NSDecimalNumber ( decimal: d) . int64Value
287311}
288312
313+ @usableFromInline
289314internal func convertDecimalToUInt64( _ d: Decimal ) -> UInt64 ? {
290315 if d > UInt64 . maxDecimal || d < UInt64 . minDecimal {
291316 return nil
0 commit comments