Skip to content

Commit

Permalink
util: add some comments
Browse files Browse the repository at this point in the history
address review comment
  • Loading branch information
c4pt0r committed Oct 13, 2015
1 parent 8b4a5f0 commit 16d0c20
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion store/localstore/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Iterator interface {
Value() []byte
// Seek moves the iterator to the first key/value pair whose key is greater
// or equal to the given key.
// It returns whether such pair exist.
// It returns whether such pair exists or not.
Seek(startKey []byte) bool
// Release releases current iterator.
Release()
Expand Down
5 changes: 5 additions & 0 deletions store/localstore/mvcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,10 @@ func (t *testMvccSuite) TestBufferedIterator(c *C) {
it, err = tx.Seek([]byte{0xff, 0xff, 0xff, 0xff}, nil)
c.Assert(err, IsNil)
c.Assert(it.Valid(), IsFalse)

it, err = tx.Seek([]byte{0x0, 0xff}, nil)
c.Assert(err, IsNil)
c.Assert(it.Valid(), IsTrue)
c.Assert(it.Value(), DeepEquals, []byte("2"))
tx.Commit()
}
2 changes: 1 addition & 1 deletion util/bytes/bytes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package bytes

// CloneBytes returns a deep copy of slice b
// CloneBytes returns a deep copy of slice b.
func CloneBytes(b []byte) []byte {
return append([]byte(nil), b...)
}
5 changes: 5 additions & 0 deletions util/bytes/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func (s *testBytesHelperSuites) TestBytesClone(c *C) {
shadowB := b
newB := CloneBytes(b)
c.Assert(b, DeepEquals, newB)
// Ugly hacks.Go doesn't allow compare two slice (except nil).
// For example: b == newB <-- it's invalid.
// In this test, we must ensure CloneBytes method returns a new slice with
// the same value, so we need to check the new slice's address.
c.Assert(fmt.Sprintf("%p", b) != fmt.Sprintf("%p", newB), IsTrue)
// But the addresses are the same when it's a shadow copy.
c.Assert(fmt.Sprintf("%p", b), Equals, fmt.Sprintf("%p", shadowB))
}

0 comments on commit 16d0c20

Please sign in to comment.