From 88924c8aa782fa696cfbfda1f8e3e17209ea21fb Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Fri, 24 Mar 2023 15:53:46 +0000 Subject: [PATCH] [Java] Avoid unnecessary array copying in tests (#247) --- .../src/testFixtures/java/ethereum/ckzg4844/TestUtils.java | 5 ----- .../ckzg4844/test_formats/BlobToKzgCommitmentTest.java | 2 +- .../ckzg4844/test_formats/ComputeBlobKzgProofTest.java | 2 +- .../ethereum/ckzg4844/test_formats/ComputeKzgProofTest.java | 2 +- .../ckzg4844/test_formats/VerifyBlobKzgProofBatchTest.java | 2 +- .../ckzg4844/test_formats/VerifyBlobKzgProofTest.java | 2 +- 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/TestUtils.java b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/TestUtils.java index 6a48cbd..4998a3c 100644 --- a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/TestUtils.java +++ b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/TestUtils.java @@ -6,7 +6,6 @@ import ethereum.ckzg4844.test_formats.*; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; -import java.io.InputStream; import java.io.UncheckedIOException; import java.math.BigInteger; import java.nio.ByteBuffer; @@ -234,10 +233,6 @@ public class TestUtils { return randomBLSFieldElement().toArray(ByteOrder.LITTLE_ENDIAN); } - private static InputStream readResource(final String resource) { - return Thread.currentThread().getContextClassLoader().getResourceAsStream(resource); - } - public static List getFiles(String path) { try { try (Stream stream = Files.list(Paths.get(path))) { diff --git a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/BlobToKzgCommitmentTest.java b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/BlobToKzgCommitmentTest.java index ef0d0da..8a6e74b 100644 --- a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/BlobToKzgCommitmentTest.java +++ b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/BlobToKzgCommitmentTest.java @@ -7,7 +7,7 @@ public class BlobToKzgCommitmentTest { private String blob; public byte[] getBlob() { - return Bytes.fromHexString(blob).toArray(); + return Bytes.fromHexString(blob).toArrayUnsafe(); } } diff --git a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/ComputeBlobKzgProofTest.java b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/ComputeBlobKzgProofTest.java index ba0e4ad..f172326 100644 --- a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/ComputeBlobKzgProofTest.java +++ b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/ComputeBlobKzgProofTest.java @@ -8,7 +8,7 @@ public class ComputeBlobKzgProofTest { private String commitment; public byte[] getBlob() { - return Bytes.fromHexString(blob).toArray(); + return Bytes.fromHexString(blob).toArrayUnsafe(); } public byte[] getCommitment() { diff --git a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/ComputeKzgProofTest.java b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/ComputeKzgProofTest.java index b5df76b..18af47e 100644 --- a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/ComputeKzgProofTest.java +++ b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/ComputeKzgProofTest.java @@ -10,7 +10,7 @@ public class ComputeKzgProofTest { private String z; public byte[] getBlob() { - return Bytes.fromHexString(blob).toArray(); + return Bytes.fromHexString(blob).toArrayUnsafe(); } public byte[] getZ() { diff --git a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/VerifyBlobKzgProofBatchTest.java b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/VerifyBlobKzgProofBatchTest.java index 7ecf432..4774c2b 100644 --- a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/VerifyBlobKzgProofBatchTest.java +++ b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/VerifyBlobKzgProofBatchTest.java @@ -15,7 +15,7 @@ public class VerifyBlobKzgProofBatchTest { return TestUtils.flatten( blobs.stream() .map(Bytes::fromHexString) - .map(Bytes::toArray) + .map(Bytes::toArrayUnsafe) .collect(Collectors.toList()) .toArray(byte[][]::new)); } diff --git a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/VerifyBlobKzgProofTest.java b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/VerifyBlobKzgProofTest.java index 43b9962..6d29a11 100644 --- a/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/VerifyBlobKzgProofTest.java +++ b/bindings/java/src/testFixtures/java/ethereum/ckzg4844/test_formats/VerifyBlobKzgProofTest.java @@ -9,7 +9,7 @@ public class VerifyBlobKzgProofTest { private String proof; public byte[] getBlob() { - return Bytes.fromHexString(blob).toArray(); + return Bytes.fromHexString(blob).toArrayUnsafe(); } public byte[] getCommitment() {