From f225b3d4a1d815e81ad1c37cc95e92be4dfad253 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Tue, 1 Jan 2019 13:47:37 -0600 Subject: [PATCH] Avoid allocating strings in common message types --- command_complete.go | 6 +++--- row_description.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/command_complete.go b/command_complete.go index 85848532..ba5a6a63 100644 --- a/command_complete.go +++ b/command_complete.go @@ -8,7 +8,7 @@ import ( ) type CommandComplete struct { - CommandTag string + CommandTag []byte } func (*CommandComplete) Backend() {} @@ -19,7 +19,7 @@ func (dst *CommandComplete) Decode(src []byte) error { return &invalidMessageFormatErr{messageType: "CommandComplete"} } - dst.CommandTag = string(src[:idx]) + dst.CommandTag = src[:idx] return nil } @@ -43,6 +43,6 @@ func (src *CommandComplete) MarshalJSON() ([]byte, error) { CommandTag string }{ Type: "CommandComplete", - CommandTag: src.CommandTag, + CommandTag: string(src.CommandTag), }) } diff --git a/row_description.go b/row_description.go index 3c5a6faa..eb504c60 100644 --- a/row_description.go +++ b/row_description.go @@ -14,7 +14,7 @@ const ( ) type FieldDescription struct { - Name string + Name []byte TableOID uint32 TableAttributeNumber uint16 DataTypeOID uint32 @@ -45,7 +45,7 @@ func (dst *RowDescription) Decode(src []byte) error { if err != nil { 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 // check Len ahead of time