зеркало из https://github.com/golang/leveldb.git
leveldb: use s[i:j:k] syntax.
R=bradfitz, dsymonds, adg CC=golang-dev https://codereview.appspot.com/15020050
This commit is contained in:
Родитель
05002c3217
Коммит
5073d6066a
|
@ -86,7 +86,8 @@ func (m *MemDB) load(kvOffset int) (b []byte) {
|
|||
return nil
|
||||
}
|
||||
bLen, n := binary.Uvarint(m.kvData[kvOffset:])
|
||||
return m.kvData[kvOffset+n : kvOffset+n+int(bLen)]
|
||||
i, j := kvOffset+n, kvOffset+n+int(bLen)
|
||||
return m.kvData[i:j:j]
|
||||
}
|
||||
|
||||
// save saves a []byte to m.kvData.
|
||||
|
|
|
@ -167,6 +167,9 @@ func Test1000Entries(t *testing.T) {
|
|||
j := r.Intn(N)
|
||||
k := []byte(strconv.Itoa(j))
|
||||
v, err := m0.Get(k, nil)
|
||||
if len(v) != cap(v) {
|
||||
t.Fatalf("get: j=%d, got len(v)=%d, cap(v)=%d", j, len(v), cap(v))
|
||||
}
|
||||
var c uint8
|
||||
if len(v) != 0 {
|
||||
c = v[0]
|
||||
|
@ -210,6 +213,12 @@ func Test1000Entries(t *testing.T) {
|
|||
if got := string(x.Key()); got != want {
|
||||
t.Fatalf("iter: got %q, want %q", got, want)
|
||||
}
|
||||
if k := x.Key(); len(k) != cap(k) {
|
||||
t.Fatalf("iter: len(k)=%d, cap(k)=%d", len(k), cap(k))
|
||||
}
|
||||
if v := x.Value(); len(v) != cap(v) {
|
||||
t.Fatalf("iter: len(v)=%d, cap(v)=%d", len(v), cap(v))
|
||||
}
|
||||
}
|
||||
if err := x.Close(); err != nil {
|
||||
t.Fatalf("close: %v", err)
|
||||
|
|
|
@ -132,7 +132,7 @@ func (i *blockIter) Key() []byte {
|
|||
if i.soi {
|
||||
return nil
|
||||
}
|
||||
return i.key
|
||||
return i.key[:len(i.key):len(i.key)]
|
||||
}
|
||||
|
||||
// Value implements Iterator.Value, as documented in the leveldb/db package.
|
||||
|
@ -140,7 +140,7 @@ func (i *blockIter) Value() []byte {
|
|||
if i.soi {
|
||||
return nil
|
||||
}
|
||||
return i.val
|
||||
return i.val[:len(i.val):len(i.val)]
|
||||
}
|
||||
|
||||
// Close implements Iterator.Close, as documented in the leveldb/db package.
|
||||
|
|
|
@ -54,6 +54,8 @@ func check(f db.File) error {
|
|||
// Check using Get.
|
||||
if v1, err := r.Get([]byte(k), nil); string(v1) != string(v) || err != nil {
|
||||
return fmt.Errorf("Get %q: got (%q, %v), want (%q, %v)", k, v1, err, v, error(nil))
|
||||
} else if len(v1) != cap(v1) {
|
||||
return fmt.Errorf("Get %q: len(v1)=%d, cap(v1)=%d", k, len(v1), cap(v1))
|
||||
}
|
||||
|
||||
// Check using Find.
|
||||
|
@ -61,9 +63,15 @@ func check(f db.File) error {
|
|||
if !i.Next() || string(i.Key()) != k {
|
||||
return fmt.Errorf("Find %q: key was not in the table", k)
|
||||
}
|
||||
if k1 := i.Key(); len(k1) != cap(k1) {
|
||||
return fmt.Errorf("Find %q: len(k1)=%d, cap(k1)=%d", k, len(k1), cap(k1))
|
||||
}
|
||||
if string(i.Value()) != v {
|
||||
return fmt.Errorf("Find %q: got value %q, want %q", k, i.Value(), v)
|
||||
}
|
||||
if v1 := i.Value(); len(v1) != cap(v1) {
|
||||
return fmt.Errorf("Find %q: len(v1)=%d, cap(v1)=%d", k, len(v1), cap(v1))
|
||||
}
|
||||
if err := i.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче