save 1-loc

This commit is contained in:
xtaci
2019-05-15 16:14:14 +08:00
parent 4299d21e8f
commit f5fa48311f
2 changed files with 13 additions and 5 deletions
+3 -4
View File
@@ -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
View File
@@ -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())
}
}