Skip to content

strconv: add equivalents of Parsexxx() with []byte arguments #2632

@remyoudompheng

Description

@remyoudompheng
Hello,

Just like we have FormatFloat(...) string and AppendFloat(...) []byte, it would be nice
to avoid a costly string conversion when parsing numbers from a byteslice.

Simple code like:

func main() {
  s := "123.45"
  r := bytes.NewBufferString(s)
  runtime.UpdateMemStats()
  println(runtime.MemStats.Mallocs)
  var v float64
  fmt.Fscanf(r, "%f", &v)
  runtime.UpdateMemStats()
  println(runtime.MemStats.Mallocs)
}

says it's doing 7 allocations in the Scanf.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions