Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reject nil/empty keys and nil values #99

Merged
merged 7 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove nonNilBytes()
  • Loading branch information
erikgrinaker committed May 18, 2020
commit 5c599b95c489f7fcc1fd47f17e1cb28af3fad763
4 changes: 2 additions & 2 deletions cleveldb_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (b *cLevelDBBatch) Set(key, value []byte) error {
if b.batch == nil {
return errBatchClosed
}
b.batch.Put(nonNilBytes(key), nonNilBytes(value))
b.batch.Put(key, value)
return nil
}

Expand All @@ -40,7 +40,7 @@ func (b *cLevelDBBatch) Delete(key []byte) error {
if b.batch == nil {
return errBatchClosed
}
b.batch.Delete(nonNilBytes(key))
b.batch.Delete(key)
return nil
}

Expand Down
1 change: 0 additions & 1 deletion goleveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (db *GoLevelDB) Get(key []byte) ([]byte, error) {
if len(key) == 0 {
return nil, errKeyEmpty
}
key = nonNilBytes(key)
res, err := db.db.Get(key, nil)
if err != nil {
if err == errors.ErrNotFound {
Expand Down
4 changes: 2 additions & 2 deletions memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func (i *item) Less(other btree.Item) bool {

// newKey creates a new key item.
func newKey(key []byte) *item {
return &item{key: nonNilBytes(key)}
return &item{key: key}
}

// newPair creates a new pair item.
func newPair(key, value []byte) *item {
return &item{key: nonNilBytes(key), value: nonNilBytes(value)}
return &item{key: key, value: value}
}

// MemDB is an in-memory database backend using a B-tree for storage.
Expand Down
9 changes: 0 additions & 9 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import (
"os"
)

// We defensively turn nil keys or values into []byte{} for
// most operations.
func nonNilBytes(bz []byte) []byte {
if bz == nil {
return []byte{}
}
return bz
}

func cp(bz []byte) (ret []byte) {
ret = make([]byte, len(bz))
copy(ret, bz)
Expand Down