Skip to content

Commit

Permalink
use nil []byte instead of zero len []byte
Browse files Browse the repository at this point in the history
  • Loading branch information
syndtr committed Jun 13, 2022
1 parent 943eb65 commit 75fe519
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions leveldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func recoverTable(s *session, o *opt.Options) error {
tSeq = seq
}
if imin == nil {
imin = append([]byte{}, key...)
imin = append([]byte(nil), key...)
}
imax = append(imax[:0], key...)
}
Expand Down Expand Up @@ -766,7 +766,7 @@ func (db *DB) get(auxm *memdb.DB, auxt tFiles, key []byte, seq uint64, ro *opt.R

if auxm != nil {
if ok, mv, me := memGet(auxm, ikey, db.s.icmp); ok {
return append([]byte{}, mv...), me
return append([]byte(nil), mv...), me
}
}

Expand All @@ -778,7 +778,7 @@ func (db *DB) get(auxm *memdb.DB, auxt tFiles, key []byte, seq uint64, ro *opt.R
defer m.decref()

if ok, mv, me := memGet(m.DB, ikey, db.s.icmp); ok {
return append([]byte{}, mv...), me
return append([]byte(nil), mv...), me
}
}

Expand Down
2 changes: 1 addition & 1 deletion leveldb/db_compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (b *tableCompactionBuilder) cleanup() {
func (b *tableCompactionBuilder) run(cnt *compactionTransactCounter) error {
snapResumed := b.snapIter > 0
hasLastUkey := b.snapHasLastUkey // The key might has zero length, so this is necessary.
lastUkey := append([]byte{}, b.snapLastUkey...)
lastUkey := append([]byte(nil), b.snapLastUkey...)
lastSeq := b.snapLastSeq
b.kerrCnt = b.snapKerrCnt
b.dropCnt = b.snapDropCnt
Expand Down
4 changes: 2 additions & 2 deletions leveldb/iterator/merged_iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (i *mergedIterator) Next() bool {
case dirSOI:
return i.First()
case dirBackward:
key := append([]byte{}, i.keys[i.index]...)
key := append([]byte(nil), i.keys[i.index]...)
if !i.Seek(key) {
return false
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func (i *mergedIterator) Prev() bool {
case dirEOI:
return i.Last()
case dirForward:
key := append([]byte{}, i.keys[i.index]...)
key := append([]byte(nil), i.keys[i.index]...)
for x, iter := range i.iters {
if x == i.index {
continue
Expand Down
2 changes: 1 addition & 1 deletion leveldb/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (e *ErrInternalKeyCorrupted) Error() string {
}

func newErrInternalKeyCorrupted(ikey []byte, reason string) error {
return errors.NewErrCorrupted(storage.FileDesc{}, &ErrInternalKeyCorrupted{append([]byte{}, ikey...), reason})
return errors.NewErrCorrupted(storage.FileDesc{}, &ErrInternalKeyCorrupted{append([]byte(nil), ikey...), reason})
}

type keyType uint
Expand Down
2 changes: 1 addition & 1 deletion leveldb/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ type tWriter struct {
// Append key/value pair to the table.
func (w *tWriter) append(key, value []byte) error {
if w.first == nil {
w.first = append([]byte{}, key...)
w.first = append([]byte(nil), key...)
}
w.last = append(w.last[:0], key...)
return w.tw.Append(key, value)
Expand Down
2 changes: 1 addition & 1 deletion leveldb/table/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ func (r *Reader) find(key []byte, filtered bool, ro *opt.ReadOptions, noValue bo
} else {
// Value does use block buffer, and since the buffer will be
// recycled, it need to be copied.
value = append([]byte{}, data.Value()...)
value = append([]byte(nil), data.Value()...)
}
}
data.Release()
Expand Down
2 changes: 1 addition & 1 deletion leveldb/testutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func BytesSeparator(a, b []byte) []byte {
}
for ; i < n && (a[i] == b[i]); i++ {
}
x := append([]byte{}, a[:i]...)
x := append([]byte(nil), a[:i]...)
if i < n {
if c := a[i] + 1; c < b[i] {
return append(x, c)
Expand Down
2 changes: 1 addition & 1 deletion manualtest/dbstress/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (e *ErrIkeyCorrupted) Error() string {
}

func newErrIkeyCorrupted(ikey []byte, reason string) error {
return errors.NewErrCorrupted(storage.FileDesc{}, &ErrIkeyCorrupted{append([]byte{}, ikey...), reason})
return errors.NewErrCorrupted(storage.FileDesc{}, &ErrIkeyCorrupted{append([]byte(nil), ikey...), reason})
}

type kType int
Expand Down

0 comments on commit 75fe519

Please sign in to comment.