Skip to content

Commit 486dc27

Browse files
authored
Merge pull request #60917 from lorentey/no-conversions-please
[stdlib] Don’t do full integer conversions in _roundUp
2 parents aa976ff + 6eddc2e commit 486dc27

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

stdlib/public/core/Builtin.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ internal func _roundUp(_ offset: UInt, toAlignment alignment: Int) -> UInt {
3939
@inlinable
4040
internal func _roundUp(_ offset: Int, toAlignment alignment: Int) -> Int {
4141
_internalInvariant(offset >= 0)
42-
return Int(_roundUpImpl(UInt(bitPattern: offset), toAlignment: alignment))
42+
let offset = UInt(bitPattern: offset)
43+
let result = Int(bitPattern: _roundUpImpl(offset, toAlignment: alignment))
44+
_internalInvariant(result >= 0)
45+
return result
4346
}
4447

4548
/// Returns a tri-state of 0 = no, 1 = yes, 2 = maybe.

0 commit comments

Comments
 (0)