Skip to content

Commit e68195b

Browse files
committed
[embedded] Avoid using UInt64 in int->string code (which triggers allocations on 32-bit systems)
1 parent 7120279 commit e68195b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

stdlib/public/core/EmbeddedPrint.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ extension BinaryInteger {
7777
internal func _toStringImpl(
7878
_ buffer: UnsafeMutablePointer<UTF8.CodeUnit>,
7979
_ bufferLength: UInt,
80-
_ radix: Int64,
80+
_ radix: Int,
8181
_ uppercase: Bool
82-
) -> UInt64 {
82+
) -> Int {
8383
if self == (0 as Self) {
8484
buffer[0] = UInt8(("0" as Unicode.Scalar).value)
8585
return 1
@@ -114,7 +114,7 @@ extension BinaryInteger {
114114
let destination = UnsafeMutableRawBufferPointer(start: buffer, count: Int(bufferLength))
115115
destination.copyMemory(from: UnsafeRawBufferPointer(intermediate))
116116
117-
return UInt64(count)
117+
return count
118118
}
119119
120120
func writeToStdout() {
@@ -127,7 +127,7 @@ extension BinaryInteger {
127127
128128
let count = _toStringImpl(buffer, 64, 10, false)
129129
130-
printCharacters(UnsafeBufferPointer(start: buffer, count: Int(count)))
130+
printCharacters(UnsafeBufferPointer(start: buffer, count: count))
131131
132132
Builtin.stackDealloc(stackBuffer)
133133
}

stdlib/public/core/Runtime.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ internal func _int64ToStringImpl(
478478
_ radix: Int64,
479479
_ uppercase: Bool
480480
) -> UInt64 {
481-
return value._toStringImpl(buffer, bufferLength, radix, uppercase)
481+
return UInt64(value._toStringImpl(buffer, bufferLength, Int(radix), uppercase))
482482
}
483483
#endif
484484

@@ -527,7 +527,7 @@ internal func _uint64ToStringImpl(
527527
_ radix: Int64,
528528
_ uppercase: Bool
529529
) -> UInt64 {
530-
return value._toStringImpl(buffer, bufferLength, radix, uppercase)
530+
return UInt64(value._toStringImpl(buffer, bufferLength, Int(radix), uppercase))
531531
}
532532
#endif
533533

0 commit comments

Comments
 (0)