Skip to content

Commit

Permalink
replace siddontang/go/hack with zeroalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Dec 15, 2024
1 parent 4a8c838 commit e700be5
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 33 deletions.
7 changes: 3 additions & 4 deletions client/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"

"github.com/pingcap/errors"
"github.com/siddontang/go/hack"

. "github.com/go-mysql-org/go-mysql/mysql"
"github.com/go-mysql-org/go-mysql/utils"
Expand Down Expand Up @@ -78,11 +77,11 @@ func (c *Conn) handleErrorPacket(data []byte) error {
if c.capability&CLIENT_PROTOCOL_41 > 0 {
// skip '#'
pos++
e.State = hack.String(data[pos : pos+5])
e.State = utils.ByteSliceToString(data[pos : pos+5])
pos += 5
}

e.Message = hack.String(data[pos:])
e.Message = utils.ByteSliceToString(data[pos:])

return e
}
Expand Down Expand Up @@ -372,7 +371,7 @@ func (c *Conn) readResultColumns(result *Result) (err error) {
return err
}

result.FieldNames[hack.String(result.Fields[i].Name)] = i
result.FieldNames[utils.ByteSliceToString(result.Fields[i].Name)] = i

i++
}
Expand Down
4 changes: 2 additions & 2 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

"github.com/go-mysql-org/go-mysql/client"
"github.com/go-mysql-org/go-mysql/mysql"
"github.com/go-mysql-org/go-mysql/utils"
"github.com/pingcap/errors"
"github.com/siddontang/go/hack"
)

var customTLSMutex sync.Mutex
Expand Down Expand Up @@ -352,7 +352,7 @@ func newRows(r *mysql.Resultset) (*rows, error) {
rs.columns = make([]string, len(r.Fields))

for i, f := range r.Fields {
rs.columns[i] = hack.String(f.Name)
rs.columns[i] = utils.ByteSliceToString(f.Name)
}
rs.step = 0

Expand Down
6 changes: 3 additions & 3 deletions mysql/mysql_gtid.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"strconv"
"strings"

"github.com/go-mysql-org/go-mysql/utils"
"github.com/google/uuid"
"github.com/pingcap/errors"
"github.com/siddontang/go/hack"
)

// Like MySQL GTID Interval struct, [start, stop), left closed and right open
Expand Down Expand Up @@ -318,7 +318,7 @@ func (s *UUIDSet) MinusInterval(in IntervalSlice) {
}

func (s *UUIDSet) String() string {
return hack.String(s.Bytes())
return utils.ByteSliceToString(s.Bytes())
}

func (s *UUIDSet) encode(w io.Writer) {
Expand Down Expand Up @@ -571,7 +571,7 @@ func (s *MysqlGTIDSet) String() string {
sep = ","
}

return hack.String(buf.Bytes())
return utils.ByteSliceToString(buf.Bytes())
}

func (s *MysqlGTIDSet) Encode() []byte {
Expand Down
4 changes: 2 additions & 2 deletions mysql/resultset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strconv"
"sync"

"github.com/go-mysql-org/go-mysql/utils"
"github.com/pingcap/errors"
"github.com/siddontang/go/hack"
)

type StreamingType int
Expand Down Expand Up @@ -263,7 +263,7 @@ func (r *Resultset) GetString(row, column int) (string, error) {
case string:
return v, nil
case []byte:
return hack.String(v), nil
return utils.ByteSliceToString(v), nil
case int, int8, int16, int32, int64,
uint, uint8, uint16, uint32, uint64:
return fmt.Sprintf("%d", v), nil
Expand Down
13 changes: 7 additions & 6 deletions mysql/resultset_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"strconv"

"github.com/pingcap/errors"
"github.com/siddontang/go/hack"

"github.com/go-mysql-org/go-mysql/utils"
)

func FormatTextValue(value interface{}) ([]byte, error) {
Expand Down Expand Up @@ -37,7 +38,7 @@ func FormatTextValue(value interface{}) ([]byte, error) {
case []byte:
return v, nil
case string:
return hack.Slice(v), nil
return utils.StringToByteSlice(v), nil
case nil:
return nil, nil
default:
Expand Down Expand Up @@ -74,7 +75,7 @@ func formatBinaryValue(value interface{}) ([]byte, error) {
case []byte:
return v, nil
case string:
return hack.Slice(v), nil
return utils.StringToByteSlice(v), nil
default:
return nil, errors.Errorf("invalid type %T", value)
}
Expand Down Expand Up @@ -128,7 +129,7 @@ func BuildSimpleTextResultset(names []string, values [][]interface{}) (*Resultse

if len(values) == 0 {
for i, name := range names {
r.Fields[i] = &Field{Name: hack.Slice(name), Charset: 33, Type: MYSQL_TYPE_NULL}
r.Fields[i] = &Field{Name: utils.StringToByteSlice(name), Charset: 33, Type: MYSQL_TYPE_NULL}
}
return r, nil
}
Expand All @@ -145,7 +146,7 @@ func BuildSimpleTextResultset(names []string, values [][]interface{}) (*Resultse
return nil, errors.Trace(err)
}
if r.Fields[j] == nil {
r.Fields[j] = &Field{Name: hack.Slice(names[j]), Type: typ}
r.Fields[j] = &Field{Name: utils.StringToByteSlice(names[j]), Type: typ}
err = formatField(r.Fields[j], value)
if err != nil {
return nil, errors.Trace(err)
Expand Down Expand Up @@ -213,7 +214,7 @@ func BuildSimpleBinaryResultset(names []string, values [][]interface{}) (*Result
if i == 0 {
field := &Field{Type: typ}
r.Fields[j] = field
field.Name = hack.Slice(names[j])
field.Name = utils.StringToByteSlice(names[j])

if err = formatField(field, value); err != nil {
return nil, errors.Trace(err)
Expand Down
4 changes: 2 additions & 2 deletions mysql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"time"

"github.com/Masterminds/semver"
"github.com/go-mysql-org/go-mysql/utils"
"github.com/pingcap/errors"
"github.com/siddontang/go/hack"
)

func Pstack() string {
Expand Down Expand Up @@ -375,7 +375,7 @@ var (
func Escape(sql string) string {
dest := make([]byte, 0, 2*len(sql))

for _, w := range hack.Slice(sql) {
for _, w := range utils.StringToByteSlice(sql) {
if c := EncodeMap[w]; c == DONTESCAPE {
dest = append(dest, w)
} else {
Expand Down
8 changes: 4 additions & 4 deletions replication/json_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"math"

"github.com/go-mysql-org/go-mysql/utils"
"github.com/goccy/go-json"
"github.com/pingcap/errors"
"github.com/siddontang/go/hack"

. "github.com/go-mysql-org/go-mysql/mysql"
)
Expand Down Expand Up @@ -243,7 +243,7 @@ func (d *jsonBinaryDecoder) decodeObjectOrArray(data []byte, isSmall bool, isObj
return nil
}

keys[i] = hack.String(data[keyOffset : keyOffset+keyLength])
keys[i] = utils.ByteSliceToString(data[keyOffset : keyOffset+keyLength])
}
}

Expand Down Expand Up @@ -411,7 +411,7 @@ func (d *jsonBinaryDecoder) decodeString(data []byte) string {

data = data[n:]

v := hack.String(data[0:l])
v := utils.ByteSliceToString(data[0:l])
return v
}

Expand Down Expand Up @@ -439,7 +439,7 @@ func (d *jsonBinaryDecoder) decodeOpaque(data []byte) interface{} {
case MYSQL_TYPE_DATE, MYSQL_TYPE_DATETIME, MYSQL_TYPE_TIMESTAMP:
return d.decodeDateTime(data)
default:
return hack.String(data)
return utils.ByteSliceToString(data)
}
}

Expand Down
8 changes: 4 additions & 4 deletions replication/row_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

"github.com/pingcap/errors"
"github.com/shopspring/decimal"
"github.com/siddontang/go/hack"

. "github.com/go-mysql-org/go-mysql/mysql"
"github.com/go-mysql-org/go-mysql/utils"
)

var errMissingTableMapEvent = errors.New("invalid table id, no corresponding table map event")
Expand Down Expand Up @@ -1393,7 +1393,7 @@ func (e *RowsEvent) decodeValue(data []byte, tp byte, meta uint16, isPartial boo
var d []byte
d, err = e.decodeJsonBinary(data[meta:n])
if err == nil {
v = hack.String(d)
v = utils.ByteSliceToString(d)
}
}
}
Expand All @@ -1417,11 +1417,11 @@ func decodeString(data []byte, length int) (v string, n int) {
length = int(data[0])

n = length + 1
v = hack.String(data[1:n])
v = utils.ByteSliceToString(data[1:n])
} else {
length = int(binary.LittleEndian.Uint16(data[0:]))
n = length + 2
v = hack.String(data[2:n])
v = utils.ByteSliceToString(data[2:n])
}

return
Expand Down
12 changes: 6 additions & 6 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/go-mysql-org/go-mysql/mysql"
. "github.com/go-mysql-org/go-mysql/mysql"
"github.com/go-mysql-org/go-mysql/replication"
"github.com/siddontang/go/hack"
"github.com/go-mysql-org/go-mysql/utils"
)

// Handler is what a server needs to implement the client-server protocol
Expand Down Expand Up @@ -81,23 +81,23 @@ func (c *Conn) dispatch(data []byte) interface{} {
c.Conn = nil
return noResponse{}
case COM_QUERY:
if r, err := c.h.HandleQuery(hack.String(data)); err != nil {
if r, err := c.h.HandleQuery(utils.ByteSliceToString(data)); err != nil {
return err
} else {
return r
}
case COM_PING:
return nil
case COM_INIT_DB:
if err := c.h.UseDB(hack.String(data)); err != nil {
if err := c.h.UseDB(utils.ByteSliceToString(data)); err != nil {
return err
} else {
return nil
}
case COM_FIELD_LIST:
index := bytes.IndexByte(data, 0x00)
table := hack.String(data[0:index])
wildcard := hack.String(data[index+1:])
table := utils.ByteSliceToString(data[0:index])
wildcard := utils.ByteSliceToString(data[index+1:])

if fs, err := c.h.HandleFieldList(table, wildcard); err != nil {
return err
Expand All @@ -108,7 +108,7 @@ func (c *Conn) dispatch(data []byte) interface{} {
c.stmtID++
st := new(Stmt)
st.ID = c.stmtID
st.Query = hack.String(data)
st.Query = utils.ByteSliceToString(data)
var err error
if st.Params, st.Columns, st.Context, err = c.h.HandleStmtPrepare(st.Query); err != nil {
return err
Expand Down

0 comments on commit e700be5

Please sign in to comment.