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)
| 474 | // a few common cases for increased efficiency. For non-hardcoded cases, it uses |
| 475 | // strconv.AppendFloat to avoid allocations, similar to writeInt. |
| 476 | func writeFloat(w enhancedWriter, f float64) (int, error) { |
| 477 | switch { |
| 478 | case f == 1: |
| 479 | return 1, w.WriteByte('1') |
| 480 | case f == 0: |
| 481 | return 1, w.WriteByte('0') |
| 482 | case f == -1: |
| 483 | return w.WriteString("-1") |
| 484 | case math.IsNaN(f): |
| 485 | return w.WriteString("NaN") |
| 486 | case math.IsInf(f, +1): |
| 487 | return w.WriteString("+Inf") |
| 488 | case math.IsInf(f, -1): |
| 489 | return w.WriteString("-Inf") |
| 490 | default: |
| 491 | bp := numBufPool.Get().(*[]byte) |
| 492 | *bp = strconv.AppendFloat((*bp)[:0], f, 'g', -1, 64) |
| 493 | written, err := w.Write(*bp) |
| 494 | numBufPool.Put(bp) |
| 495 | return written, err |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | // writeInt is equivalent to fmt.Fprint with an int64 argument but uses |
| 500 | // strconv.AppendInt with a byte slice taken from a sync.Pool to avoid |
no test coverage detected
searching dependent graphs…