writeFloat is equivalent to fmt.Fprint with a float64 argument but hardcodes a few common cases for increased efficiency. For non-hardcoded cases, it uses strconv.AppendFloat to avoid allocations, similar to writeInt.
(w enhancedWriter, f float64)
| 430 | // a few common cases for increased efficiency. For non-hardcoded cases, it uses |
| 431 | // strconv.AppendFloat to avoid allocations, similar to writeInt. |
| 432 | func writeFloat(w enhancedWriter, f float64) (int, error) { |
| 433 | switch { |
| 434 | case f == 1: |
| 435 | return 1, w.WriteByte('1') |
| 436 | case f == 0: |
| 437 | return 1, w.WriteByte('0') |
| 438 | case f == -1: |
| 439 | return w.WriteString("-1") |
| 440 | case math.IsNaN(f): |
| 441 | return w.WriteString("NaN") |
| 442 | case math.IsInf(f, +1): |
| 443 | return w.WriteString("+Inf") |
| 444 | case math.IsInf(f, -1): |
| 445 | return w.WriteString("-Inf") |
| 446 | default: |
| 447 | bp := numBufPool.Get().(*[]byte) |
| 448 | *bp = strconv.AppendFloat((*bp)[:0], f, 'g', -1, 64) |
| 449 | written, err := w.Write(*bp) |
| 450 | numBufPool.Put(bp) |
| 451 | return written, err |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | // writeInt is equivalent to fmt.Fprint with an int64 argument but uses |
| 456 | // strconv.AppendInt with a byte slice taken from a sync.Pool to avoid |
no test coverage detected