Improve prepared statement performance
* Do not use bufio.Writer - use net.Conn directly * Use byte slice instead of bytes.Buffer when building query message * Use binary.BigEndian.* instead of binary.Write
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package pgx_test
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/jackc/pgx"
|
||||
"io"
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
@@ -57,19 +55,15 @@ func decodePointFromText(mr *pgx.MessageReader, size int32) interface{} {
|
||||
return p
|
||||
}
|
||||
|
||||
func encodePoint(w io.Writer, value interface{}) error {
|
||||
func encodePoint(w *pgx.WriteBuf, value interface{}) error {
|
||||
p, ok := value.(Point)
|
||||
if !ok {
|
||||
return fmt.Errorf("Expected Point, received %T", value)
|
||||
}
|
||||
|
||||
s := fmt.Sprintf("point(%v,%v)", p.x, p.y)
|
||||
w.WriteInt32(int32(len(s)))
|
||||
w.WriteBytes([]byte(s))
|
||||
|
||||
err := binary.Write(w, binary.BigEndian, int32(len(s)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.WriteString(w, s)
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user