Skip to content

Commit

Permalink
codec: improve buffer reuse (#10801)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing authored and zz-jason committed Jul 23, 2019
1 parent 899ff96 commit 18724b9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion store/mockstore/mocktikv/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (e *indexScanExec) decodeIndexKV(pair Pair) ([][]byte, error) {
} else {
handleDatum = types.NewIntDatum(handle)
}
handleBytes, err := codec.EncodeValue(nil, b, handleDatum)
handleBytes, err := codec.EncodeValue(nil, nil, handleDatum)
if err != nil {
return nil, errors.Trace(err)
}
Expand Down
4 changes: 2 additions & 2 deletions tablecodec/tablecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ func EncodeRow(sc *stmtctx.StatementContext, row []types.Datum, colIDs []int64,
values[2*i].SetInt64(id)
err := flatten(sc, c, &values[2*i+1])
if err != nil {
return nil, errors.Trace(err)
return valBuf, errors.Trace(err)
}
}
if len(values) == 0 {
// We could not set nil value into kv.
return []byte{codec.NilFlag}, nil
return append(valBuf, codec.NilFlag), nil
}
return codec.EncodeValue(sc, valBuf, values...)
}
Expand Down
6 changes: 3 additions & 3 deletions util/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func encode(sc *stmtctx.StatementContext, b []byte, vals []types.Datum, comparab
b = append(b, uintFlag)
b, err = EncodeMySQLTime(sc, vals[i], mysql.TypeUnspecified, b)
if err != nil {
return nil, err
return b, err
}
case types.KindMysqlDuration:
// duration may have negative value, so we cannot use String to encode directly.
Expand All @@ -107,7 +107,7 @@ func encode(sc *stmtctx.StatementContext, b []byte, vals []types.Datum, comparab
var bin []byte
bin, err = dec.ToHashKey()
if err != nil {
return nil, errors.Trace(err)
return b, errors.Trace(err)
}
b = append(b, bin...)
} else {
Expand Down Expand Up @@ -140,7 +140,7 @@ func encode(sc *stmtctx.StatementContext, b []byte, vals []types.Datum, comparab
case types.KindMaxValue:
b = append(b, maxFlag)
default:
return nil, errors.Errorf("unsupport encode type %d", vals[i].Kind())
return b, errors.Errorf("unsupport encode type %d", vals[i].Kind())
}
}

Expand Down

0 comments on commit 18724b9

Please sign in to comment.