You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2023/07/29 20:27:02 UTC

[groovy] branch master updated: Add the missing `clone` method to `FastArray`

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

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new f20715d97c Add the missing `clone` method to `FastArray`
f20715d97c is described below

commit f20715d97cb421b8fc5b2d61e09689b79a4c7b4a
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Jul 30 04:26:26 2023 +0800

    Add the missing `clone` method to `FastArray`
---
 src/main/java/org/codehaus/groovy/util/FastArray.java | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/util/FastArray.java b/src/main/java/org/codehaus/groovy/util/FastArray.java
index 6d0e4b2de3..8ee775a2cb 100644
--- a/src/main/java/org/codehaus/groovy/util/FastArray.java
+++ b/src/main/java/org/codehaus/groovy/util/FastArray.java
@@ -26,9 +26,9 @@ import java.util.List;
 
 public class FastArray implements Cloneable, Serializable {
     private static final long serialVersionUID = -9143440116071577249L;
+    public static final FastArray EMPTY_LIST = new FastArray(0);
     private Object[] data;
     public int size;
-    public static final FastArray EMPTY_LIST = new FastArray(0);
 
     public FastArray(int initialCapacity) {
         data = new Object[initialCapacity];
@@ -141,4 +141,16 @@ public class FastArray implements Cloneable, Serializable {
         if (size() == 0) return "[]";
         return toList().toString();
     }
+
+    @Override
+    public FastArray clone() {
+        try {
+            FastArray clone = (FastArray) super.clone();
+            clone.size = size;
+            clone.data = data.clone();
+            return clone;
+        } catch (CloneNotSupportedException e) {
+            throw new AssertionError();
+        }
+    }
 }