Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: all: use io.WriteString instead of byteslice(string) conversion #16851

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
perf: all: use io.WriteString instead of byteslice(string) conversion
This change switches to using io.WriteString instead of a primitive
[]byte(str) conversion.
  • Loading branch information
odeke-em committed Jul 6, 2023
commit 4b270d34c464360c1d6acb559bdeea8aa5470c5a
8 changes: 4 additions & 4 deletions collections/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (m Map[K, V]) importGenesis(ctx context.Context, reader io.Reader) error {
}

func (m Map[K, V]) exportGenesis(ctx context.Context, writer io.Writer) error {
_, err := writer.Write([]byte("["))
_, err := io.WriteString(writer, "[")
if err != nil {
return err
}
Expand All @@ -48,7 +48,7 @@ func (m Map[K, V]) exportGenesis(ctx context.Context, writer io.Writer) error {
// add a comma before encoding the object
// for all objects besides the first one.
if !first {
_, err = writer.Write([]byte(","))
_, err = io.WriteString(writer, ",")
if err != nil {
return err
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func (m Map[K, V]) exportGenesis(ctx context.Context, writer io.Writer) error {
}
}

_, err = writer.Write([]byte("]"))
_, err = io.WriteString(writer, "]")
return err
}

Expand Down Expand Up @@ -148,6 +148,6 @@ func (m Map[K, V]) doDecodeJSON(reader io.Reader, onEntry func(key K, value V) e
}

func (m Map[K, V]) defaultGenesis(writer io.Writer) error {
_, err := writer.Write([]byte(`[]`))
_, err := io.WriteString(writer, `[]`)
return err
}
2 changes: 1 addition & 1 deletion orm/encoding/ormfield/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s NonTerminalStringCodec) Encode(value protoreflect.Value, w io.Writer) er
return fmt.Errorf("illegal null terminator found in index string: %s", str)
}
}
_, err := w.Write([]byte(str))
_, err := w.Write(bz)
if err != nil {
return err
}
Expand Down