Skip to content

fmt: pp should implement WriteString() #20786

Closed
@pierrre

Description

@pierrre

What version of Go are you using (go version)?

1.9beta1

What did you do?

In my code, I'm implementing fmt.Formatter.
In order to write a string to the fmt.State, I'm calling io.WriteString().
I know that this function has an optimization that allows to call WriteString() if w implements it.
Sadly, in my case the "real" type of fmt.State is fmt.pp.
fmt.pp only has Write().

What did you expect to see?

I think we should add:

func (p *pp) WriteString(s string) (ret int, err error) {
	p.buf.WriteString(s)
	return len(s), nil
}

in my case, it greatly improve performance and reduces memory allocation.
We could also implement WriteByte() and WriteRune(), since fmt.buffer has these methods.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions