You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2019/08/27 18:28:47 UTC

[commons-compress] 02/02: generic version of Arrays.copyOf is slower than copying manually

This is an automated email from the ASF dual-hosted git repository.

bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 9d2a2f4a520db29fb1f1bf064979fed0efb7f075
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Tue Aug 27 20:28:03 2019 +0200

    generic version of Arrays.copyOf is slower than copying manually
    
    thanks @Tibor17
---
 .../apache/commons/compress/archivers/zip/ZipArchiveEntry.java   | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
index 767f615..30f8479 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
@@ -27,8 +27,6 @@ import java.util.Date;
 import java.util.List;
 import java.util.zip.ZipException;
 
-import static java.util.Arrays.copyOf;
-
 /**
  * Extension that adds better handling of extra fields and provides
  * access to the internal and external file attributes.
@@ -812,7 +810,7 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
      */
     public byte[] getRawName() {
         if (rawName != null) {
-            return copyOf(rawName, rawName.length);
+            return Arrays.copyOf(rawName, rawName.length);
         }
         return null;
     }
@@ -1082,6 +1080,11 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry
         this.commentSource = commentSource;
     }
 
+    private ZipExtraField[] copyOf(final ZipExtraField[] src, final int length) {
+        final ZipExtraField[] cpy = new ZipExtraField[length];
+        System.arraycopy(src, 0, cpy, 0, Math.min(src.length, length));
+        return cpy;
+    }
 
     /**
      * How to try to parse the extra fields.