mirror of
https://github.com/xtaci/smux.git
synced 2024-04-21 10:51:48 +00:00
save 1-loc
This commit is contained in:
@@ -55,11 +55,10 @@ func (alloc *Allocator) Put(buf []byte) error {
|
||||
// msb return the pos of most significiant bit
|
||||
func msb(size int) uint16 {
|
||||
var pos uint16
|
||||
for {
|
||||
size >>= 1
|
||||
for size > 0 {
|
||||
size >>= 1
|
||||
if size == 0 {
|
||||
return pos
|
||||
}
|
||||
pos++
|
||||
}
|
||||
return pos
|
||||
}
|
||||
|
||||
+10
-1
@@ -1,6 +1,9 @@
|
||||
package smux
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAllocGet(t *testing.T) {
|
||||
alloc := NewAllocator()
|
||||
@@ -70,3 +73,9 @@ func TestAllocPutThenGet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMSB(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
msb(rand.Int())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user