Skip to content

Commit da8e9de

Browse files
committed
[stdlib] refactor precondition() for consistency
1 parent f1ff695 commit da8e9de

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

stdlib/public/core/Assert.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,18 @@ public func precondition(
8585
_ message: @autoclosure () -> String = String(),
8686
file: StaticString = #file, line: UInt = #line
8787
) {
88-
// Only check in debug and release mode. In release mode just trap.
89-
if _isDebugAssertConfiguration() {
90-
if !_fastPath(condition()) {
88+
// Only check in debug and release mode.
89+
if _isDebugAssertConfiguration() || _isReleaseAssertConfiguration() {
90+
if _fastPath(condition()) {
91+
return
92+
}
93+
if _isDebugAssertConfiguration() {
9194
_assertionFailure("Precondition failed", message(), file: file, line: line,
9295
flags: _fatalErrorFlags())
96+
} else { // In release mode just trap.
97+
let message = StaticString("precondition failure")
98+
Builtin.condfail_message(true._value, message.unsafeRawPointer)
9399
}
94-
} else if _isReleaseAssertConfiguration() {
95-
let error = !condition()
96-
Builtin.condfail_message(error._value,
97-
StaticString("precondition failure").unsafeRawPointer)
98100
}
99101
}
100102

0 commit comments

Comments
 (0)