From dd1db989f44b833a812e4e2c61bc963bd5bc35cc Mon Sep 17 00:00:00 2001 From: silentsai Date: Mon, 21 Jul 2014 17:48:44 +0800 Subject: [PATCH] optimize memory cost while iterating data segments in bitmap --- ledis/t_bit.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ledis/t_bit.go b/ledis/t_bit.go index ab14a7d..fa9c6a8 100644 --- a/ledis/t_bit.go +++ b/ledis/t_bit.go @@ -255,7 +255,7 @@ func (db *DB) bDelete(t *tx, key []byte) (drop int64) { maxKey := db.bEncodeBinKey(key, maxSeq) it := db.db.RangeIterator(minKey, maxKey, leveldb.RangeClose) for ; it.Valid(); it.Next() { - t.Delete(it.Key()) + t.Delete(it.RawKey()) drop++ } it.Close() @@ -450,14 +450,14 @@ func (db *DB) BGet(key []byte) (data []byte, err error) { var seq, s, e uint32 for ; it.Valid(); it.Next() { - if _, seq, err = db.bDecodeBinKey(it.Key()); err != nil { + if _, seq, err = db.bDecodeBinKey(it.RawKey()); err != nil { data = nil break } s = seq << segByteWidth e = MinUInt32(s+segByteSize, capByteSize) - copy(data[s:e], it.Value()) + copy(data[s:e], it.RawValue()) } it.Close() @@ -664,7 +664,7 @@ func (db *DB) BCount(key []byte, start int32, end int32) (cnt int32, err error) it := db.db.RangeIterator(skey, ekey, leveldb.RangeOpen) for ; it.Valid(); it.Next() { - segment = it.Value() + segment = it.RawValue() for _, bt := range segment { cnt += bitsInByte[bt] } @@ -777,12 +777,12 @@ func (db *DB) BOperation(op uint8, dstkey []byte, srckeys ...[]byte) (blen int32 // ps : init segments by data corresponding to the 1st valid source key it := db.bIterator(srckeys[srcIdx]) for ; it.Valid(); it.Next() { - if _, seq, err = db.bDecodeBinKey(it.Key()); err != nil { + if _, seq, err = db.bDecodeBinKey(it.RawKey()); err != nil { // to do ... it.Close() return } - segments[seq] = it.Value() + segments[seq] = it.RawValue() } it.Close() srcIdx++ @@ -799,7 +799,7 @@ func (db *DB) BOperation(op uint8, dstkey []byte, srckeys ...[]byte) (blen int32 for idx, end := uint32(0), false; !end; it.Next() { end = !it.Valid() if !end { - if _, seq, err = db.bDecodeBinKey(it.Key()); err != nil { + if _, seq, err = db.bDecodeBinKey(it.RawKey()); err != nil { // to do ... it.Close() return @@ -820,7 +820,7 @@ func (db *DB) BOperation(op uint8, dstkey []byte, srckeys ...[]byte) (blen int32 } if !end { - res = it.Value() + res = it.RawValue() exeOp(segments[seq], res, &res) segments[seq] = res idx++