Skip to content

Commit fe4aca6

Browse files
authored
[NFC] Optimize logging code (#650)
1 parent b069bf8 commit fe4aca6

File tree

22 files changed

+77
-65
lines changed

22 files changed

+77
-65
lines changed

Sources/OpenSwiftUI/App/FinishLaunchTestAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct FinishLaunchTestAction {
1717
#if os(iOS) || os(visionOS)
1818
UIApplication.shared.finishedTest(UIApplication.shared._launchTestName())
1919
#else
20-
preconditionFailure("Unimplemented for other platform")
20+
_openSwiftUIPlatformUnimplementedWarning()
2121
#endif
2222
}
2323
}

Sources/OpenSwiftUI/Integration/Representable/Platform/PlatformViewRepresentable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,11 @@ struct PlatformArchivedDisplayList<Content>: Rule where Content: PlatformViewRep
621621
}
622622

623623
func makePlatformView() -> AnyObject? {
624-
preconditionFailure("")
624+
_openSwiftUIUnreachableCode()
625625
}
626626

627627
func updatePlatformView(_ view: inout AnyObject) {
628-
preconditionFailure("")
628+
_openSwiftUIUnreachableCode()
629629
}
630630
}
631631
}

Sources/OpenSwiftUI/View/Control/Link/OpenURLActionKey.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct OpenURLActionKey: EnvironmentKey {
2626
completion(error != nil)
2727
}
2828
#else
29-
preconditionFailure("Unimplemented")
29+
_openSwiftUIPlatformUnimplementedWarning()
3030
#endif
3131
},
3232
isDefault: true
@@ -51,7 +51,7 @@ struct OpenSensitiveURLActionKey: EnvironmentKey {
5151
}
5252
workspace.open(url, configuration: config, completionHandler: completion)
5353
#else
54-
preconditionFailure("Unimplemented")
54+
_openSwiftUIPlatformUnimplementedWarning()
5555
#endif
5656
},
5757
isDefault: true

Sources/OpenSwiftUICore/Data/DynamicProperty/DynamicProperty.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,10 @@ extension BodyAccessor {
324324
inputs: inout _GraphInputs,
325325
fields: DynamicPropertyCache.Fields
326326
) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
327-
guard Body.self != Never.self else {
328-
preconditionFailure("\(Container.self) may not have Body == Never")
329-
}
327+
precondition(
328+
Body.self != Never.self,
329+
"\(Container.self) may not have Body == Never"
330+
)
330331
return withUnsafePointer(to: inputs) { pointer in
331332
func project<Flags>(flags _: Flags.Type) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) where Flags: RuleThreadFlags {
332333
let buffer = _DynamicPropertyBuffer(

Sources/OpenSwiftUICore/Data/Protobuf/ProtobufDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ extension ProtobufDecoder {
473473
/// - Returns: The decodable value resulting from the plist data.
474474
func value<T>(fromBinaryPlist data: Data, type: T.Type = T.self) throws -> T where T: Decodable {
475475
#if os(WASI)
476-
preconditionFailure("PropertyListDecoder is not avaiable on WASI")
476+
_openSwiftUIPlatformUnimplementedFailure()
477477
#else
478478
let decoder = PropertyListDecoder()
479479
decoder.userInfo = userInfo

Sources/OpenSwiftUICore/Data/Protobuf/ProtobufEncoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ extension ProtobufEncoder {
415415
/// - Returns: The encoded binary plist data.
416416
func binaryPlistData<T>(for value: T) throws -> Data where T: Encodable {
417417
#if os(WASI)
418-
preconditionFailure("PropertyListEncoder is not avaiable on WASI")
418+
_openSwiftUIPlatformUnimplementedFailure()
419419
#else
420420
let encoder = PropertyListEncoder()
421421
encoder.outputFormat = .binary

Sources/OpenSwiftUICore/Data/Update.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ package enum Update {
6060
guard lockAssertionsAreEnabled else {
6161
return
6262
}
63-
guard isOwner else {
64-
preconditionFailure("OpenSwiftUI is active without having taken its own lock - missing Update.ensure()?")
65-
}
63+
precondition(
64+
isOwner,
65+
"OpenSwiftUI is active without having taken its own lock - missing Update.ensure()?"
66+
)
6667
}
6768

6869
package static func begin() {
@@ -184,10 +185,10 @@ package enum Update {
184185
}
185186
for action in actions {
186187
action()
187-
let newDepth = depth
188-
guard newDepth == oldDepth else {
189-
preconditionFailure("Action caused unbalanced updates.")
190-
}
188+
precondition(
189+
depth == oldDepth,
190+
"Action caused unbalanced updates."
191+
)
191192
}
192193
}
193194
}

Sources/OpenSwiftUICore/Layout/Dynamic/DynamicContainer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ struct DynamicContainerInfo<Adapter>: StatefulRule, AsyncAttribute, ObservedAttr
629629
}
630630
switch phase {
631631
case .willAppear:
632-
preconditionFailure("")
632+
_openSwiftUIUnreachableCode()
633633
case .identity:
634634
guard !disableTransitions, info.items[index].needsTransitions else {
635635
eraseItem(at: index)
@@ -696,7 +696,7 @@ struct DynamicContainerInfo<Adapter>: StatefulRule, AsyncAttribute, ObservedAttr
696696
let phase = info.items[index].phase
697697
switch phase {
698698
case .willAppear, nil:
699-
preconditionFailure("")
699+
_openSwiftUIUnreachableCode()
700700
case .identity:
701701
break
702702
case .didDisappear:

Sources/OpenSwiftUICore/Layout/Geometry/LayoutTraits.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,11 @@ public struct _LayoutTraits: Equatable {
5959
}
6060

6161
private func _checkInvariant() {
62-
guard min >= 0,
63-
min.isFinite,
64-
ideal < .infinity,
65-
min <= ideal,
66-
ideal <= max
67-
else {
68-
preconditionFailure("malformed dimension \(self)")
69-
}
62+
precondition(
63+
min >= 0 && min.isFinite && ideal < .infinity &&
64+
min <= ideal && ideal <= max,
65+
"malformed dimension \(self)"
66+
)
7067
}
7168
}
7269

Sources/OpenSwiftUICore/Layout/Layout.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,9 +1700,10 @@ public struct LayoutSubview: Equatable {
17001700

17011701
package func place(at position: CGPoint, anchor: UnitPoint = .topLeading, dimensions: ViewDimensions) {
17021702
let origin = CGRect(position: position, size: dimensions.size.value, anchor: anchor).origin
1703-
guard !origin.isNaN else {
1704-
preconditionFailure("view origin is invalid: \(position), \(anchor), \(dimensions.size.value)")
1705-
}
1703+
precondition(
1704+
!origin.isNaN,
1705+
"view origin is invalid: \(position), \(anchor), \(dimensions.size.value)"
1706+
)
17061707
place(in: ViewGeometry(origin: origin, dimensions: dimensions))
17071708
}
17081709

0 commit comments

Comments
 (0)