Skip to content

Commit

Permalink
*: use bytes.Equal to check byte slice equivalent (#11706) (#16174)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Apr 13, 2020
1 parent fc1d679 commit 3f6a2b9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ func (e *AnalyzeFastExec) getNextSampleKey(bo *tikv.Backoffer, startKey kv.Key)
if err != nil {
return nil, err
}
if bytes.Compare(loc.StartKey, e.sampTasks[prefixLen].Location.EndKey) == 0 {
if bytes.Equal(loc.StartKey, e.sampTasks[prefixLen].Location.EndKey) {
startKey = loc.StartKey
break
}
Expand Down
7 changes: 6 additions & 1 deletion executor/load_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package executor

import (
"bytes"
"context"
"fmt"
"strings"
Expand All @@ -30,6 +31,10 @@ import (
"go.uber.org/zap"
)

var (
null = []byte("NULL")
)

// LoadDataExec represents a load data executor.
type LoadDataExec struct {
baseExecutor
Expand Down Expand Up @@ -486,7 +491,7 @@ func (e *LoadDataInfo) getFieldsFromLine(line []byte) ([]field, error) {
for {
eol, f := reader.GetField()
f = f.escape()
if string(f.str) == "NULL" && !f.enclosed {
if bytes.Equal(f.str, null) && !f.enclosed {
f.str = []byte{'N'}
f.maybeNull = true
}
Expand Down
2 changes: 1 addition & 1 deletion store/tikv/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func (c *RegionCache) loadRegion(bo *Backoffer, key []byte, isEndKey bool) (*Reg
if len(meta.Peers) == 0 {
return nil, errors.New("receive Region with no peer")
}
if isEndKey && !searchPrev && bytes.Compare(meta.StartKey, key) == 0 && len(meta.StartKey) != 0 {
if isEndKey && !searchPrev && bytes.Equal(meta.StartKey, key) && len(meta.StartKey) != 0 {
searchPrev = true
continue
}
Expand Down

0 comments on commit 3f6a2b9

Please sign in to comment.