Skip to content

Commit

Permalink
Remove PadToPowerOf2 function (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanc authored Nov 8, 2024
1 parent d1603f2 commit 9aeea05
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
22 changes: 0 additions & 22 deletions core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,3 @@ func NextPowerOf2[T constraints.Integer](d T) T {
nextPower := math.Ceil(math.Log2(float64(d)))
return T(math.Pow(2.0, nextPower))
}

// PadToPowerOf2 pads a byte slice to the nearest power of 2 length by appending zeros
func PadToPowerOf2(data []byte) []byte {
length := len(data)
if length == 0 {
return []byte{0}
}

// If length is already a power of 2, return original
if length&(length-1) == 0 {
return data
}

// Create a new slice with the power-of-2 length
paddedData := make([]byte, NextPowerOf2(uint64(len(data))))

// Copy original data
copy(paddedData, data)

// The remaining bytes will be zero by default
return paddedData
}
4 changes: 2 additions & 2 deletions disperser/encoder/server_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestEncodeBlob(t *testing.T) {
t.FailNow()
}

return core.PadToPowerOf2(codec.ConvertByPaddingEmptyByte(data))
return codec.ConvertByPaddingEmptyByte(data)
}

// Setup test data
Expand All @@ -68,7 +68,7 @@ func TestEncodeBlob(t *testing.T) {
blobLength := encoding.GetBlobLength(blobSize)

// Get chunk length for blob version 0
chunkLength, err := corev2.GetChunkLength(0, uint32(blobLength))
chunkLength, err := corev2.GetChunkLength(0, core.NextPowerOf2(uint32(blobLength)))
if !assert.NoError(t, err, "Failed to get chunk length") {
t.FailNow()
}
Expand Down

0 comments on commit 9aeea05

Please sign in to comment.