2
0

Avoid allocating strings in common message types

This commit is contained in:
Jack Christensen
2019-01-01 13:47:37 -06:00
parent 64b1ecf96f
commit f225b3d4a1
2 changed files with 5 additions and 5 deletions
+3 -3
View File
@@ -8,7 +8,7 @@ import (
) )
type CommandComplete struct { type CommandComplete struct {
CommandTag string CommandTag []byte
} }
func (*CommandComplete) Backend() {} func (*CommandComplete) Backend() {}
@@ -19,7 +19,7 @@ func (dst *CommandComplete) Decode(src []byte) error {
return &invalidMessageFormatErr{messageType: "CommandComplete"} return &invalidMessageFormatErr{messageType: "CommandComplete"}
} }
dst.CommandTag = string(src[:idx]) dst.CommandTag = src[:idx]
return nil return nil
} }
@@ -43,6 +43,6 @@ func (src *CommandComplete) MarshalJSON() ([]byte, error) {
CommandTag string CommandTag string
}{ }{
Type: "CommandComplete", Type: "CommandComplete",
CommandTag: src.CommandTag, CommandTag: string(src.CommandTag),
}) })
} }
+2 -2
View File
@@ -14,7 +14,7 @@ const (
) )
type FieldDescription struct { type FieldDescription struct {
Name string Name []byte
TableOID uint32 TableOID uint32
TableAttributeNumber uint16 TableAttributeNumber uint16
DataTypeOID uint32 DataTypeOID uint32
@@ -45,7 +45,7 @@ func (dst *RowDescription) Decode(src []byte) error {
if err != nil { if err != nil {
return err return err
} }
fd.Name = string(bName[:len(bName)-1]) fd.Name = bName[:len(bName)-1]
// Since buf.Next() doesn't return an error if we hit the end of the buffer // Since buf.Next() doesn't return an error if we hit the end of the buffer
// check Len ahead of time // check Len ahead of time