Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/ExtrasJSON/ArrayKey.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#if !hasFeature(Embedded)
struct ArrayKey: CodingKey, Equatable {
init(index: Int) {
self.intValue = index
Expand All @@ -24,3 +24,4 @@ func == (lhs: ArrayKey, rhs: ArrayKey) -> Bool {
precondition(rhs.intValue != nil)
return lhs.intValue == rhs.intValue
}
#endif
3 changes: 2 additions & 1 deletion Sources/ExtrasJSON/Decoding/JSONDecoder.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#if !hasFeature(Embedded)
public struct XJSONDecoder {
public var userInfo: [CodingUserInfoKey: Any] = [:]

Expand Down Expand Up @@ -80,3 +80,4 @@ extension JSONDecoderImpl: Decoder {
)
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/ExtrasJSON/Decoding/JSONKeyedDecodingContainer.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !hasFeature(Embedded)
struct JSONKeyedDecodingContainer<K: CodingKey>: KeyedDecodingContainerProtocol {
typealias Key = K

Expand Down Expand Up @@ -188,3 +189,4 @@ extension JSONKeyedDecodingContainer {
return floatingPoint
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#if !hasFeature(Embedded)
struct JSONSingleValueDecodingContainter: SingleValueDecodingContainer {
let impl: JSONDecoderImpl
let value: JSONValue
Expand Down Expand Up @@ -121,3 +121,4 @@ extension JSONSingleValueDecodingContainter {
return floatingPoint
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#if !hasFeature(Embedded)
struct JSONUnkeyedDecodingContainer: UnkeyedDecodingContainer {
let impl: JSONDecoderImpl
let codingPath: [CodingKey]
Expand Down Expand Up @@ -205,3 +205,4 @@ extension JSONUnkeyedDecodingContainer {
return float
}
}
#endif
31 changes: 31 additions & 0 deletions Sources/ExtrasJSON/EmbeddedHelpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#if hasFeature(Embedded)
@inlinable
public func memmove(dest: UnsafeMutableRawPointer,
src: UnsafeRawPointer,
size: Int) {
if size <= 0 || dest == src { return }

let d = dest.bindMemory(to: UInt8.self, capacity: size)
let s = src.bindMemory(to: UInt8.self, capacity: size)

// Compare raw addresses to detect overlap direction
let dAddr = UInt(bitPattern: d)
let sAddr = UInt(bitPattern: s)

if sAddr < dAddr && dAddr < sAddr &+ UInt(size) {
// Overlap and dest starts inside src: copy backwards
var i = size
while i > 0 {
i &-= 1
d[i] = s[i]
}
} else {
// No harmful overlap: copy forwards
var i = 0
while i < size {
d[i] = s[i]
i &+= 1
}
}
}
#endif
3 changes: 2 additions & 1 deletion Sources/ExtrasJSON/Encoding/JSONEncoder.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#if !hasFeature(Embedded)
enum JSONFuture {
case value(JSONValue)
case nestedArray(JSONArray)
Expand Down Expand Up @@ -179,3 +179,4 @@ extension JSONEncoderImpl: Encoder {
return JSONSingleValueEncodingContainer(impl: self, codingPath: self.codingPath)
}
}
#endif
3 changes: 2 additions & 1 deletion Sources/ExtrasJSON/Encoding/JSONKeyedEncodingContainer.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#if !hasFeature(Embedded)
struct JSONKeyedEncodingContainer<K: CodingKey>: KeyedEncodingContainerProtocol {
typealias Key = K

Expand Down Expand Up @@ -141,3 +141,4 @@ extension JSONKeyedEncodingContainer {
self.object.set(.number(value.description), for: key.stringValue)
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#if !hasFeature(Embedded)
struct JSONSingleValueEncodingContainer: SingleValueEncodingContainer {
let impl: JSONEncoderImpl
let codingPath: [CodingKey]
Expand Down Expand Up @@ -107,3 +107,4 @@ extension JSONSingleValueEncodingContainer {
self.impl.singleValue = .number(value.description)
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#if !hasFeature(Embedded)
struct JSONUnkeyedEncodingContainer: UnkeyedEncodingContainer {
let impl: JSONEncoderImpl
let array: JSONArray
Expand Down Expand Up @@ -136,3 +136,4 @@ extension JSONUnkeyedEncodingContainer {
self.array.append(.number(value.description))
}
}
#endif
Loading