Skip to content

Commit ef6cdd0

Browse files
authored
Merge pull request #14448 from xwu/itoa-reviewer-comments
[stdlib] Address reviewer comments for consolidated integer-to-string conversion
2 parents 8b9e6ef + 26dac8f commit ef6cdd0

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

stdlib/public/core/Integers.swift.gyb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,9 +1687,7 @@ extension BinaryInteger {
16871687
@_inlineable // FIXME(sil-serialize-all)
16881688
@_versioned
16891689
@_transparent
1690-
internal func _description(
1691-
radix: Int = 10, uppercase: Bool = false
1692-
) -> String {
1690+
internal func _description(radix: Int, uppercase: Bool) -> String {
16931691
_precondition(2...36 ~= radix, "Radix must be between 2 and 36")
16941692

16951693
if bitWidth <= 64 {
@@ -1707,14 +1705,14 @@ extension BinaryInteger {
17071705
// (although not necessarily the case for builtin types).
17081706
let isRadixPowerOfTwo = radix.nonzeroBitCount == 1
17091707
let radix_ = Magnitude(radix)
1710-
let quotientAndRemainder: (Magnitude) -> (Magnitude, Magnitude) = { value in
1708+
func _quotientAndRemainder(_ value: Magnitude) -> (Magnitude, Magnitude) {
17111709
return isRadixPowerOfTwo
17121710
? (value >> radix.trailingZeroBitCount, value & (radix_ - 1))
17131711
: value.quotientAndRemainder(dividingBy: radix_)
17141712
}
17151713

17161714
let hasLetters = radix > 10
1717-
let ascii: (UInt8) -> UInt8 = { digit in
1715+
func _ascii(_ digit: UInt8) -> UInt8 {
17181716
let base: UInt8
17191717
if !hasLetters || digit < 10 {
17201718
base = UInt8(("0" as Unicode.Scalar).value)
@@ -1730,8 +1728,8 @@ extension BinaryInteger {
17301728
var value = magnitude
17311729
var result: [UInt8] = []
17321730
while value != 0 {
1733-
let (quotient, remainder) = quotientAndRemainder(value)
1734-
result.append(ascii(UInt8(truncatingIfNeeded: remainder)))
1731+
let (quotient, remainder) = _quotientAndRemainder(value)
1732+
result.append(_ascii(UInt8(truncatingIfNeeded: remainder)))
17351733
value = quotient
17361734
}
17371735

@@ -1745,7 +1743,7 @@ extension BinaryInteger {
17451743
/// A textual representation of this value.
17461744
@_inlineable // FIXME(sil-serialize-all)
17471745
public var description: String {
1748-
return _description()
1746+
return _description(radix: 10, uppercase: false)
17491747
}
17501748
}
17511749

0 commit comments

Comments
 (0)