Skip to content

Commit 65b19d8

Browse files
committed
Use the new compiler inline annotations when available
1 parent 85501c4 commit 65b19d8

File tree

3 files changed

+519
-216
lines changed

3 files changed

+519
-216
lines changed

Sources/JBirdCodableSupport/CodingKeys/SnakeCaseCodingKey.swift

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,25 @@ struct SnakeCaseCodingKey: CodingKey {
4747
var out = String()
4848
out.reserveCapacity(bytes.count + bytes.count / 4)
4949

50-
@inline(__always)
51-
func appendLowercasedASCII(_ b: UInt8) {
52-
if isUpper(b) {
53-
out.append(Character(UnicodeScalar(b + 32)))
54-
} else {
55-
out.append(Character(UnicodeScalar(b)))
50+
#if compiler(>=6.3)
51+
@inline(always)
52+
func appendLowercasedASCII(_ b: UInt8) {
53+
if isUpper(b) {
54+
out.append(Character(UnicodeScalar(b + 32)))
55+
} else {
56+
out.append(Character(UnicodeScalar(b)))
57+
}
5658
}
57-
}
59+
#else
60+
@inline(__always)
61+
func appendLowercasedASCII(_ b: UInt8) {
62+
if isUpper(b) {
63+
out.append(Character(UnicodeScalar(b + 32)))
64+
} else {
65+
out.append(Character(UnicodeScalar(b)))
66+
}
67+
}
68+
#endif
5869

5970
for i in bytes.indices {
6071
let b = bytes[i]

Sources/JBirdCore/Deserialization/Deserialization.swift

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -736,33 +736,65 @@ extension JSON {
736736
#endif
737737

738738
#if os(Windows)
739-
@inline(__always)
740-
private static func calculateMaxDepth() -> size_t {
741-
var low: ULONG_PTR = 0
742-
var high: ULONG_PTR = 0
743-
GetCurrentThreadStackLimits(&low, &high)
744-
745-
let stackBytes = size_t(high &- low)
746-
return min(1024, max(16, stackBytes / 512))
747-
}
748-
739+
#if compiler(>=6.3)
740+
@inline(always)
741+
private static func calculateMaxDepth() -> size_t {
742+
var low: ULONG_PTR = 0
743+
var high: ULONG_PTR = 0
744+
GetCurrentThreadStackLimits(&low, &high)
745+
746+
let stackBytes = size_t(high &- low)
747+
return min(1024, max(16, stackBytes / 512))
748+
}
749+
#else
750+
@inline(__always)
751+
private static func calculateMaxDepth() -> size_t {
752+
var low: ULONG_PTR = 0
753+
var high: ULONG_PTR = 0
754+
GetCurrentThreadStackLimits(&low, &high)
755+
756+
let stackBytes = size_t(high &- low)
757+
return min(1024, max(16, stackBytes / 512))
758+
}
759+
#endif
749760
#elseif os(WASI) || arch(wasm32)
750-
@inline(__always)
751-
private static func calculateMaxDepth() -> size_t {
752-
// There is no way to do this on Web Assembly. Makes sense.
753-
256
754-
}
761+
#if compiler(>=6.3)
762+
@inline(always)
763+
private static func calculateMaxDepth() -> size_t {
764+
// There is no way to do this on Web Assembly. Makes sense.
765+
256
766+
}
767+
#else
768+
@inline(__always)
769+
private static func calculateMaxDepth() -> size_t {
770+
// There is no way to do this on Web Assembly. Makes sense.
771+
256
772+
}
773+
#endif
755774
#else
756-
@inline(__always)
757-
private static func calculateMaxDepth() -> size_t {
758-
var attr = pthread_attr_t()
759-
pthread_attr_init(&attr)
760-
defer { pthread_attr_destroy(&attr) }
761-
762-
var size: size_t = 0
763-
pthread_attr_getstacksize(&attr, &size)
764-
return min(1024, max(16, size / 512))
765-
}
775+
#if compiler(>=6.3)
776+
@inline(always)
777+
private static func calculateMaxDepth() -> size_t {
778+
var attr = pthread_attr_t()
779+
pthread_attr_init(&attr)
780+
defer { pthread_attr_destroy(&attr) }
781+
782+
var size: size_t = 0
783+
pthread_attr_getstacksize(&attr, &size)
784+
return min(1024, max(16, size / 512))
785+
}
786+
#else
787+
@inline(__always)
788+
private static func calculateMaxDepth() -> size_t {
789+
var attr = pthread_attr_t()
790+
pthread_attr_init(&attr)
791+
defer { pthread_attr_destroy(&attr) }
792+
793+
var size: size_t = 0
794+
pthread_attr_getstacksize(&attr, &size)
795+
return min(1024, max(16, size / 512))
796+
}
797+
#endif
766798
#endif
767799

768800
private static func calculateMaxInputSize() -> size_t {

0 commit comments

Comments
 (0)