You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by do...@apache.org on 2022/08/04 18:30:54 UTC
[orc] branch main updated: ORC-827: Utilize Array copyOf
This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/main by this push:
new d00f59918 ORC-827: Utilize Array copyOf
d00f59918 is described below
commit d00f59918a7d0ecfd527897d2331bea74ae8dbb2
Author: David Mollitor <dm...@apache.org>
AuthorDate: Thu Aug 4 11:30:37 2022 -0700
ORC-827: Utilize Array copyOf
### What changes were proposed in this pull request?
Utilize JDK Array copyOf
### Why are the changes needed?
Less code, small performance boost perhaps
### How was this patch tested?
Existing unit tests as functionality has not changed.
Closes #732 from belugabehr/ORC-827.
Lead-authored-by: David Mollitor <dm...@apache.org>
Co-authored-by: Dongjoon Hyun <do...@apache.org>
Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
java/core/src/java/org/apache/orc/InMemoryKeystore.java | 6 ++----
java/core/src/java/org/apache/orc/impl/DynamicByteArray.java | 5 ++---
java/core/src/java/org/apache/orc/impl/DynamicIntArray.java | 6 +++---
java/core/src/java/org/apache/orc/impl/mask/SHA256MaskFactory.java | 3 +--
4 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/java/core/src/java/org/apache/orc/InMemoryKeystore.java b/java/core/src/java/org/apache/orc/InMemoryKeystore.java
index 743e3052b..f1c68ee7a 100644
--- a/java/core/src/java/org/apache/orc/InMemoryKeystore.java
+++ b/java/core/src/java/org/apache/orc/InMemoryKeystore.java
@@ -151,8 +151,7 @@ public class InMemoryKeystore implements KeyProvider {
final EncryptionAlgorithm algorithm = secret.getAlgorithm();
byte[] encryptedKey = new byte[algorithm.keyLength()];
random.nextBytes(encryptedKey);
- byte[] iv = new byte[algorithm.getIvLength()];
- System.arraycopy(encryptedKey, 0, iv, 0, iv.length);
+ byte[] iv = Arrays.copyOf(encryptedKey, algorithm.getIvLength());
Cipher localCipher = algorithm.createCipher();
try {
@@ -204,8 +203,7 @@ public class InMemoryKeystore implements KeyProvider {
}
final EncryptionAlgorithm algorithm = secret.getAlgorithm();
- byte[] iv = new byte[algorithm.getIvLength()];
- System.arraycopy(encryptedKey, 0, iv, 0, iv.length);
+ byte[] iv = Arrays.copyOf(encryptedKey, algorithm.getIvLength());
Cipher localCipher = algorithm.createCipher();
try {
diff --git a/java/core/src/java/org/apache/orc/impl/DynamicByteArray.java b/java/core/src/java/org/apache/orc/impl/DynamicByteArray.java
index fa8e0a01d..a3b5b3c7d 100644
--- a/java/core/src/java/org/apache/orc/impl/DynamicByteArray.java
+++ b/java/core/src/java/org/apache/orc/impl/DynamicByteArray.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
+import java.util.Arrays;
/**
* A class that is a growable array of bytes. Growth is managed in terms of
@@ -56,9 +57,7 @@ public final class DynamicByteArray {
if (chunkIndex >= initializedChunks) {
if (chunkIndex >= data.length) {
int newSize = Math.max(chunkIndex + 1, 2 * data.length);
- byte[][] newChunk = new byte[newSize][];
- System.arraycopy(data, 0, newChunk, 0, data.length);
- data = newChunk;
+ data = Arrays.copyOf(data, newSize);
}
for(int i=initializedChunks; i <= chunkIndex; ++i) {
data[i] = new byte[chunkSize];
diff --git a/java/core/src/java/org/apache/orc/impl/DynamicIntArray.java b/java/core/src/java/org/apache/orc/impl/DynamicIntArray.java
index fb531ce2d..3c8474efc 100644
--- a/java/core/src/java/org/apache/orc/impl/DynamicIntArray.java
+++ b/java/core/src/java/org/apache/orc/impl/DynamicIntArray.java
@@ -17,6 +17,8 @@
*/
package org.apache.orc.impl;
+import java.util.Arrays;
+
/**
* Dynamic int array that uses primitive types and chunks to avoid copying
* large number of integers when it resizes.
@@ -57,9 +59,7 @@ public final class DynamicIntArray {
if (chunkIndex >= initializedChunks) {
if (chunkIndex >= data.length) {
int newSize = Math.max(chunkIndex + 1, 2 * data.length);
- int[][] newChunk = new int[newSize][];
- System.arraycopy(data, 0, newChunk, 0, data.length);
- data = newChunk;
+ data = Arrays.copyOf(data, newSize);
}
for (int i=initializedChunks; i <= chunkIndex; ++i) {
data[i] = new int[chunkSize];
diff --git a/java/core/src/java/org/apache/orc/impl/mask/SHA256MaskFactory.java b/java/core/src/java/org/apache/orc/impl/mask/SHA256MaskFactory.java
index 837d53cd2..4b5740851 100644
--- a/java/core/src/java/org/apache/orc/impl/mask/SHA256MaskFactory.java
+++ b/java/core/src/java/org/apache/orc/impl/mask/SHA256MaskFactory.java
@@ -120,8 +120,7 @@ public class SHA256MaskFactory extends MaskFactory {
targetLength = schema.getMaxLength();
/* pad the hash with blank char if targetlength is greater than hash */
if (targetLength > hash.length) {
- byte[] tmp = new byte[targetLength];
- System.arraycopy(hash, 0, tmp, 0, hash.length);
+ byte[] tmp = Arrays.copyOf(hash, targetLength);
Arrays.fill(tmp, hash.length, tmp.length - 1, (byte) ' ');
hash = tmp;
}