Skip to content

Commit 377c66b

Browse files
Replace some precondition with _precondition in the stdlib. (#82641)
1 parent 0c20222 commit 377c66b

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

stdlib/public/core/Integers.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,9 +3083,9 @@ extension UnsignedInteger where Self: FixedWidthInteger {
30833083
_ dividend: (high: Self, low: Magnitude)
30843084
) -> (quotient: Self, remainder: Self) {
30853085
// Validate preconditions to guarantee that the quotient is representable.
3086-
precondition(self != .zero, "Division by zero")
3087-
precondition(dividend.high < self,
3088-
"Dividend.high must be smaller than divisor")
3086+
_precondition(self != .zero, "Division by zero")
3087+
_precondition(dividend.high < self,
3088+
"Dividend.high must be smaller than divisor")
30893089
// UnsignedInteger should have a Magnitude = Self constraint, but does not,
30903090
// so we have to do this conversion (we can't easily add the constraint
30913091
// because it changes how generic signatures constrained to
@@ -3330,8 +3330,8 @@ extension SignedInteger where Self: FixedWidthInteger {
33303330
// It is possible that the quotient is representable but its magnitude
33313331
// is not representable as Self (if quotient is Self.min), so we have
33323332
// to handle that case carefully here.
3333-
precondition(unsignedQuotient <= Self.min.magnitude,
3334-
"Quotient is not representable.")
3333+
_precondition(unsignedQuotient <= Self.min.magnitude,
3334+
"Quotient is not representable.")
33353335
quotient = Self(truncatingIfNeeded: 0 &- unsignedQuotient)
33363336
} else {
33373337
quotient = Self(unsignedQuotient)

stdlib/public/core/UTF8SpanFundamentals.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension UTF8Span {
1717
///
1818
/// `i` must be scalar-aligned.
1919
internal func _previousScalarStart(_ i: Int) -> Int {
20-
precondition(_boundsCheck(i&-1))
20+
_precondition(_boundsCheck(i&-1))
2121
return _previousScalarStart(unchecked: i)
2222
}
2323

@@ -31,7 +31,7 @@ extension UTF8Span {
3131
/// this is an unsafe operation.
3232
internal func _previousScalarStart(unchecked i: Int) -> Int {
3333
_internalInvariant(_boundsCheck(i&-1))
34-
precondition(_isScalarAligned(unchecked: i))
34+
_precondition(_isScalarAligned(unchecked: i))
3535
return _previousScalarStart(uncheckedAssumingAligned: i)
3636
}
3737

@@ -81,7 +81,7 @@ extension UTF8Span {
8181
internal func _decodePreviousScalar(
8282
_ i: Int
8383
) -> (Unicode.Scalar, previousScalarStart: Int) {
84-
precondition(_boundsCheck(i &- 1))
84+
_precondition(_boundsCheck(i &- 1))
8585
return _decodePreviousScalar(unchecked: i)
8686
}
8787

@@ -96,7 +96,7 @@ extension UTF8Span {
9696
unchecked i: Int
9797
) -> (Unicode.Scalar, previousScalarStart: Int) {
9898
_internalInvariant(_boundsCheck(i &- 1))
99-
precondition(_isScalarAligned(unchecked: i))
99+
_precondition(_isScalarAligned(unchecked: i))
100100
return _decodePreviousScalar(uncheckedAssumingAligned: i)
101101
}
102102

@@ -127,7 +127,7 @@ extension UTF8Span {
127127
internal func _scalarAlignBackwards(_ i: Int) -> Int {
128128
if i == count || i == 0 { return i }
129129

130-
precondition(_boundsCheck(i))
130+
_precondition(_boundsCheck(i))
131131
return unsafe _start()._scalarAlign(i)
132132
}
133133

@@ -169,7 +169,7 @@ extension UTF8Span {
169169
///
170170
/// `i` must be `Character`-aligned.
171171
internal func _nextCharacterStart(_ i: Int) -> Int {
172-
precondition(_boundsCheck(i))
172+
_precondition(_boundsCheck(i))
173173
return _nextCharacterStart(unchecked: i)
174174
}
175175

@@ -183,7 +183,7 @@ extension UTF8Span {
183183
/// this is an unsafe operation.
184184
internal func _nextCharacterStart(unchecked i: Int) -> Int {
185185
_internalInvariant(_boundsCheck(i))
186-
precondition(_isScalarAligned(unchecked: i))
186+
_precondition(_isScalarAligned(unchecked: i))
187187
return _nextCharacterStart(uncheckedAssumingAligned: i)
188188
}
189189

@@ -212,7 +212,7 @@ extension UTF8Span {
212212
///
213213
/// `i` must be `Character`-aligned.
214214
internal func _previousCharacterStart(_ i: Int) -> Int {
215-
precondition(_boundsCheck(i&-1))
215+
_precondition(_boundsCheck(i&-1))
216216
return _previousCharacterStart(unchecked: i)
217217
}
218218

@@ -226,7 +226,7 @@ extension UTF8Span {
226226
/// this is an unsafe operation.
227227
internal func _previousCharacterStart(unchecked i: Int) -> Int {
228228
_internalInvariant(_boundsCheck(i&-1))
229-
precondition(_isScalarAligned(unchecked: i))
229+
_precondition(_isScalarAligned(unchecked: i))
230230
return _previousCharacterStart(uncheckedAssumingAligned: i)
231231
}
232232

@@ -256,7 +256,7 @@ extension UTF8Span {
256256
internal func _decodeNextCharacter(
257257
_ i: Int
258258
) -> (Character, nextCharacterStart: Int) {
259-
precondition(_boundsCheck(i))
259+
_precondition(_boundsCheck(i))
260260
return _decodeNextCharacter(unchecked: i)
261261
}
262262

@@ -271,7 +271,7 @@ extension UTF8Span {
271271
unchecked i: Int
272272
) -> (Character, nextCharacterStart: Int) {
273273
_internalInvariant(_boundsCheck(i))
274-
precondition(_isScalarAligned(unchecked: i))
274+
_precondition(_isScalarAligned(unchecked: i))
275275
return _decodeNextCharacter(uncheckedAssumingAligned: i)
276276
}
277277

@@ -299,7 +299,7 @@ extension UTF8Span {
299299
///
300300
/// `i` must be `Character`-aligned.
301301
internal func _decodePreviousCharacter(_ i: Int) -> (Character, Int) {
302-
precondition(_boundsCheck(i &- 1))
302+
_precondition(_boundsCheck(i &- 1))
303303
return _decodePreviousCharacter(unchecked: i)
304304
}
305305

@@ -314,7 +314,7 @@ extension UTF8Span {
314314
unchecked i: Int
315315
) -> (Character, Int) {
316316
_internalInvariant(_boundsCheck(i &- 1))
317-
precondition(_isScalarAligned(unchecked: i))
317+
_precondition(_isScalarAligned(unchecked: i))
318318
return _decodePreviousCharacter(uncheckedAssumingAligned: i)
319319
}
320320

0 commit comments

Comments
 (0)