From 9aeea059dccb4433f27be6ffdcf05614ab2529a1 Mon Sep 17 00:00:00 2001 From: Daniel Mancia <21249320+dmanc@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:26:51 -0800 Subject: [PATCH] Remove PadToPowerOf2 function (#877) --- core/utils.go | 22 ---------------------- disperser/encoder/server_v2_test.go | 4 ++-- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/core/utils.go b/core/utils.go index 38a4b50102..479e61a872 100644 --- a/core/utils.go +++ b/core/utils.go @@ -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 -} diff --git a/disperser/encoder/server_v2_test.go b/disperser/encoder/server_v2_test.go index 90d507aa43..53ad3dce50 100644 --- a/disperser/encoder/server_v2_test.go +++ b/disperser/encoder/server_v2_test.go @@ -59,7 +59,7 @@ func TestEncodeBlob(t *testing.T) { t.FailNow() } - return core.PadToPowerOf2(codec.ConvertByPaddingEmptyByte(data)) + return codec.ConvertByPaddingEmptyByte(data) } // Setup test data @@ -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() }