From 87616e1c0322316a183d1362cad7f1053dbfe2f9 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 5 Nov 2019 15:57:46 -0800 Subject: [PATCH] use better math --- storage/sector/store.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/storage/sector/store.go b/storage/sector/store.go index 40192b49d..0112e3f4a 100644 --- a/storage/sector/store.go +++ b/storage/sector/store.go @@ -1,10 +1,11 @@ package sector import ( + "bytes" "context" "fmt" "io" - "math" + "math/bits" "sync" "github.com/filecoin-project/go-sectorbuilder/sealing_state" @@ -61,16 +62,15 @@ func (s *Store) SectorStatus(sid uint64) (*sectorbuilder.SectorSealingStatus, er } func computePaddedSize(size uint64) uint64 { - // TODO: there is a better way to compute the log2 of an integer... i'm just lazy - logv := uint64(math.Log2(float64(size))) + logv := 64 - bits.LeadingZeros64(size) - sectSize := uint64(1 << (logv + 1)) + sectSize := uint64(1 << logv) bound := sectorbuilder.UserBytesForSectorSize(sectSize) if size <= bound { return bound } - return sectorbuilder.UserBytesForSectorSize(1 << (logv + 2)) + return sectorbuilder.UserBytesForSectorSize(1 << (logv + 1)) } type nullReader struct{}