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

This commit is contained in:
Emmanuel T Odeke
2023-07-06 09:21:11 +00:00
committed by GitHub
parent acce343a1d
commit 4b557c97e8
2 changed files with 5 additions and 5 deletions
+4 -4
View File
@@ -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
}
@@ -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
}
@@ -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
}
@@ -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
}
+1 -1
View File
@@ -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
}