Skip to content

Commit 35f149b

Browse files
committed
optimize(ctxext): storage
1 parent fe73385 commit 35f149b

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

ctxext/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s Storage) SaveTo(ctx *zero.Ctx, gid int64) error {
4141
// Get bmp is a continuous 1's sequence like 0x00ff00
4242
func (s Storage) Get(bmp int64) int64 {
4343
sft := bits.TrailingZeros64(uint64(bmp))
44-
return (int64(s) & bmp) >> int64(sft)
44+
return (int64(s) >> int64(sft)) & (bmp >> int64(sft))
4545
}
4646

4747
// Set bmp is a continuous 1's sequence like 0x00ff00
@@ -50,7 +50,7 @@ func (s Storage) Set(x int64, bmp int64) Storage {
5050
panic("cannot use bmp == 0")
5151
}
5252
sft := bits.TrailingZeros64(uint64(bmp))
53-
return Storage((int64(s) & (^bmp)) | ((x & (bmp >> int64(sft))) << int64(sft)))
53+
return Storage((int64(s) & (^bmp)) | ((x << int64(sft)) & bmp))
5454
}
5555

5656
// GetBool bmp must be 1-bit-long

0 commit comments

Comments
 (0)