Skip to content

Commit 2bf38bf

Browse files
committed
Remove a layer of indirection
1 parent de7c280 commit 2bf38bf

File tree

1 file changed

+53
-96
lines changed

1 file changed

+53
-96
lines changed

stdlib/public/core/FloatingPointToString.swift

Lines changed: 53 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,8 @@ public func _float16ToStringImpl(
155155
return UInt64(truncatingIfNeeded: textLength)
156156
}
157157

158-
internal func _Float16ToASCII(
159-
value f: Float16,
160-
buffer utf8Buffer: inout MutableSpan<UTF8.CodeUnit>
161-
) -> Range<Int> {
162-
if #available(SwiftStdlib 6.2, *) {
163-
return _Float16ToASCIIImpl(value: f, buffer: &utf8Buffer)
164-
} else {
165-
return 0..<0
166-
}
167-
}
168-
169158
@available(SwiftStdlib 6.2, *)
170-
fileprivate func _Float16ToASCIIImpl(
159+
internal func _Float16ToASCII(
171160
value f: Float16,
172161
buffer utf8Buffer: inout MutableSpan<UTF8.CodeUnit>
173162
) -> Range<Int> {
@@ -429,36 +418,29 @@ public func _float32ToStringImpl(
429418
_ value: Float32,
430419
_ debug: Bool
431420
) -> UInt64 {
432-
// Code below works with raw memory.
433-
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
434-
_unchecked: textBuffer,
435-
count: Int(bufferLength))
436-
let textRange = _Float32ToASCII(value: value, buffer: &buffer)
437-
let textLength = textRange.upperBound - textRange.lowerBound
438-
439-
// Move the text to the start of the buffer
440-
if textRange.lowerBound != 0 {
441-
unsafe _memmove(
442-
dest: textBuffer,
443-
src: textBuffer + textRange.lowerBound,
444-
size: UInt(truncatingIfNeeded: textLength))
445-
}
446-
return UInt64(truncatingIfNeeded: textLength)
447-
}
448-
449-
internal func _Float32ToASCII(
450-
value f: Float32,
451-
buffer utf8Buffer: inout MutableSpan<UTF8.CodeUnit>
452-
) -> Range<Int> {
453421
if #available(SwiftStdlib 6.2, *) {
454-
return _Float32ToASCIIImpl(value: f, buffer: &utf8Buffer)
422+
// Code below works with raw memory.
423+
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
424+
_unchecked: textBuffer,
425+
count: Int(bufferLength))
426+
let textRange = _Float32ToASCII(value: value, buffer: &buffer)
427+
let textLength = textRange.upperBound - textRange.lowerBound
428+
429+
// Move the text to the start of the buffer
430+
if textRange.lowerBound != 0 {
431+
unsafe _memmove(
432+
dest: textBuffer,
433+
src: textBuffer + textRange.lowerBound,
434+
size: UInt(truncatingIfNeeded: textLength))
435+
}
436+
return UInt64(truncatingIfNeeded: textLength)
455437
} else {
456-
return 0..<0
438+
fatalError()
457439
}
458440
}
459441

460442
@available(SwiftStdlib 6.2, *)
461-
fileprivate func _Float32ToASCIIImpl(
443+
internal func _Float32ToASCII(
462444
value f: Float32,
463445
buffer utf8Buffer: inout MutableSpan<UTF8.CodeUnit>
464446
) -> Range<Int> {
@@ -681,36 +663,29 @@ public func _float64ToStringImpl(
681663
_ value: Float64,
682664
_ debug: Bool
683665
) -> UInt64 {
684-
// Code below works with raw memory.
685-
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
686-
_unchecked: textBuffer,
687-
count: Int(bufferLength))
688-
let textRange = _Float64ToASCII(value: value, buffer: &buffer)
689-
let textLength = textRange.upperBound - textRange.lowerBound
690-
691-
// Move the text to the start of the buffer
692-
if textRange.lowerBound != 0 {
693-
unsafe _memmove(
694-
dest: textBuffer,
695-
src: textBuffer + textRange.lowerBound,
696-
size: UInt(truncatingIfNeeded: textLength))
697-
}
698-
return UInt64(truncatingIfNeeded: textLength)
699-
}
700-
701-
internal func _Float64ToASCII(
702-
value d: Float64,
703-
buffer utf8Buffer: inout MutableSpan<UTF8.CodeUnit>
704-
) -> Range<Int> {
705666
if #available(SwiftStdlib 6.2, *) {
706-
return _Float64ToASCIIImpl(value: d, buffer: &utf8Buffer)
667+
// Code below works with raw memory.
668+
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
669+
_unchecked: textBuffer,
670+
count: Int(bufferLength))
671+
let textRange = _Float64ToASCII(value: value, buffer: &buffer)
672+
let textLength = textRange.upperBound - textRange.lowerBound
673+
674+
// Move the text to the start of the buffer
675+
if textRange.lowerBound != 0 {
676+
unsafe _memmove(
677+
dest: textBuffer,
678+
src: textBuffer + textRange.lowerBound,
679+
size: UInt(truncatingIfNeeded: textLength))
680+
}
681+
return UInt64(truncatingIfNeeded: textLength)
707682
} else {
708-
return 0..<0
683+
fatalError()
709684
}
710685
}
711686

712687
@available(SwiftStdlib 6.2, *)
713-
fileprivate func _Float64ToASCIIImpl(
688+
internal func _Float64ToASCII(
714689
value d: Float64,
715690
buffer utf8Buffer: inout MutableSpan<UTF8.CodeUnit>
716691
) -> Range<Int> {
@@ -1186,36 +1161,29 @@ internal func _float80ToStringImpl(
11861161
_ value: Float80,
11871162
_ debug: Bool
11881163
) -> UInt64 {
1189-
// Code below works with raw memory.
1190-
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
1191-
_unchecked: textBuffer,
1192-
count: Int(bufferLength))
1193-
let textRange = _Float80ToASCII(value: value, buffer: &buffer)
1194-
let textLength = textRange.upperBound - textRange.lowerBound
1195-
1196-
// Move the text to the start of the buffer
1197-
if textRange.lowerBound != 0 {
1198-
unsafe _memmove(
1199-
dest: textBuffer,
1200-
src: textBuffer + textRange.lowerBound,
1201-
size: UInt(truncatingIfNeeded: textLength))
1202-
}
1203-
return UInt64(truncatingIfNeeded: textLength)
1204-
}
1205-
1206-
internal func _Float80ToASCII(
1207-
value d: Float80,
1208-
buffer utf8Buffer: inout MutableSpan<UTF8.CodeUnit>
1209-
) -> Range<Int> {
12101164
if #available(SwiftStdlib 6.2, *) {
1211-
return _Float80ToASCIIImpl(value: d, buffer: &utf8Buffer)
1165+
// Code below works with raw memory.
1166+
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
1167+
_unchecked: textBuffer,
1168+
count: Int(bufferLength))
1169+
let textRange = _Float80ToASCII(value: value, buffer: &buffer)
1170+
let textLength = textRange.upperBound - textRange.lowerBound
1171+
1172+
// Move the text to the start of the buffer
1173+
if textRange.lowerBound != 0 {
1174+
unsafe _memmove(
1175+
dest: textBuffer,
1176+
src: textBuffer + textRange.lowerBound,
1177+
size: UInt(truncatingIfNeeded: textLength))
1178+
}
1179+
return UInt64(truncatingIfNeeded: textLength)
12121180
} else {
1213-
return 0..<0
1181+
fatalError()
12141182
}
12151183
}
12161184

12171185
@available(SwiftStdlib 6.2, *)
1218-
fileprivate func _Float80ToASCIIImpl(
1186+
internal func _Float80ToASCII(
12191187
value f: Float80,
12201188
buffer utf8Buffer: inout MutableSpan<UTF8.CodeUnit>
12211189
) -> Range<Int> {
@@ -1336,19 +1304,8 @@ fileprivate func _Float80ToASCIIImpl(
13361304
// backwards compatibility, and the legacy ABI never supported
13371305
// Float128.
13381306

1339-
internal func _Float128ToASCII(
1340-
value d: Float128,
1341-
buffer utf8Buffer: inout MutableSpan<UTF8.CodeUnit>
1342-
) -> Range<Int> {
1343-
if #available(SwiftStdlib 6.2, *) {
1344-
return _Float128ToASCIIImpl(value: d, buffer: &utf8Buffer)
1345-
} else {
1346-
return 0..<0
1347-
}
1348-
}
1349-
13501307
@available(SwiftStdlib 6.2, *)
1351-
fileprivate func _Float128ToASCIIImpl(
1308+
internal func _Float128ToASCII(
13521309
value d: Float128,
13531310
buffer utf8Buffer: inout MutableSpan<UTF8.CodeUnit>
13541311
) -> Range<Int> {

0 commit comments

Comments
 (0)