Skip to content

Commit deccd0a

Browse files
committed
Minor safety and performance tweaks
1 parent 7902b41 commit deccd0a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

stdlib/public/core/FloatingPointToString.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ internal func _Float16ToASCII(
264264
nextDigit &+= 1
265265
}
266266
}
267-
let digit = 0x30 &+ (t &+ (1 &<< 27)) >> 28
267+
let digit = 0x30 &+ (t &+ (1 << 27)) >> 28
268268
unsafe buffer.storeBytes(
269269
of: UInt8(truncatingIfNeeded: digit),
270270
toUncheckedByteOffset: nextDigit,
@@ -606,7 +606,7 @@ internal func _Float32ToASCII(
606606

607607
// Adjust the final digit to be closer to the original value
608608
let isBoundary = (f.significandBitPattern == 0)
609-
if delta > t &+ (1 &<< fractionBits) {
609+
if delta > t &+ (1 << fractionBits) {
610610
let skew: UInt64
611611
if isBoundary {
612612
skew = delta &- delta / 3 &- t
@@ -698,15 +698,15 @@ internal func _Float64ToASCII(
698698
//
699699
let binaryExponent: Int
700700
let significand: Double.RawSignificand
701-
let exponentBias = (1 << (Double.exponentBitCount - 1)) - 2 // 1022
701+
let exponentBias = 1022 // (1 << (Double.exponentBitCount - 1)) - 2
702702

703703
if (d.exponentBitPattern == 0x7ff) {
704704
if (d.isInfinite) {
705705
return _infinity(buffer: &buffer, sign: d.sign)
706706
} else { // d.isNaN
707707
let quietBit =
708708
(d.significandBitPattern >> (Double.significandBitCount - 1)) & 1
709-
let payloadMask = (UInt64(1) << (Double.significandBitCount - 2)) - 1
709+
let payloadMask = (UInt64(1) &<< (Double.significandBitCount - 2)) - 1
710710
let payload64 = d.significandBitPattern & payloadMask
711711
return nan_details(
712712
buffer: &buffer,
@@ -1649,9 +1649,9 @@ fileprivate func _finishFormatting(
16491649
let zeroEnd = firstDigit &+ base10Exponent &+ 3
16501650
// TODO: Find out how to use C memset() here:
16511651
// Blast 8 "0" digits into the buffer
1652-
unsafe buffer.storeBytes(
1652+
buffer.storeBytes(
16531653
of: 0x3030303030303030 as UInt64,
1654-
toUncheckedByteOffset: nextDigit,
1654+
toByteOffset: nextDigit,
16551655
as: UInt64.self)
16561656
// Add more "0" digits if needed...
16571657
// (Note: Can't use a standard range loop because nextDigit+8

0 commit comments

Comments
 (0)