summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-09-07 10:50:55 +0000
committerpaltherr <paltherr@epfl.ch>2003-09-07 10:50:55 +0000
commit7e8533ec4275548c8fe13d78f8872b932a806956 (patch)
tree4f65e2cde88eebfeed3873fe4409e17d4cab6f05 /sources
parentd107eb40f1372ab1a1b9b26220e55c512d44ecd7 (diff)
downloadscala-7e8533ec4275548c8fe13d78f8872b932a806956.tar.gz
scala-7e8533ec4275548c8fe13d78f8872b932a806956.tar.bz2
scala-7e8533ec4275548c8fe13d78f8872b932a806956.zip
- Added additional cloneArray methods
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/ast/Tree.java.tmpl32
-rw-r--r--sources/scalac/symtab/Symbol.java32
-rw-r--r--sources/scalac/symtab/Type.java32
3 files changed, 87 insertions, 9 deletions
diff --git a/sources/scalac/ast/Tree.java.tmpl b/sources/scalac/ast/Tree.java.tmpl
index 868bdda09a..ca2f06242a 100644
--- a/sources/scalac/ast/Tree.java.tmpl
+++ b/sources/scalac/ast/Tree.java.tmpl
@@ -133,9 +133,35 @@ public class Tree {
/** Returns a shallow copy of the given array. */
public static Tree[] cloneArray(Tree[] array) {
- if (array.length == 0) return array;
- Tree[] clone = new Tree[array.length];
- for (int i = 0; i < clone.length; i++) clone[i] = array[i];
+ return cloneArray(0, array, 0);
+ }
+
+ /**
+ * Returns a shallow copy of the given array prefixed by "prefix"
+ * null items.
+ */
+ public static Tree[] cloneArray(int prefix, Tree[] array) {
+ return cloneArray(prefix, array, 0);
+ }
+
+ /**
+ * Returns a shallow copy of the given array suffixed by "suffix"
+ * null items.
+ */
+ public static Tree[] cloneArray(Tree[] array, int suffix) {
+ return cloneArray(0, array, suffix);
+ }
+
+ /**
+ * Returns a shallow copy of the given array prefixed by "prefix"
+ * null items and suffixed by "suffix" null items.
+ */
+ public static Tree[] cloneArray(int prefix, Tree[] array, int suffix) {
+ assert prefix >= 0 && suffix >= 0: prefix + " - " + suffix;
+ int size = prefix + array.length + suffix;
+ if (size == 0) return EMPTY_ARRAY;
+ Tree[] clone = new Tree[size];
+ for (int i = 0; i < array.length; i++) clone[prefix + i] = array[i];
return clone;
}
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index fa595e51ff..3fe0b5f554 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -86,9 +86,35 @@ public abstract class Symbol implements Modifiers, Kinds {
/** Returns a shallow copy of the given array. */
public static Symbol[] cloneArray(Symbol[] array) {
- if (array.length == 0) return array;
- Symbol[] clone = new Symbol[array.length];
- for (int i = 0; i < clone.length; i++) clone[i] = array[i];
+ return cloneArray(0, array, 0);
+ }
+
+ /**
+ * Returns a shallow copy of the given array prefixed by "prefix"
+ * null items.
+ */
+ public static Symbol[] cloneArray(int prefix, Symbol[] array) {
+ return cloneArray(prefix, array, 0);
+ }
+
+ /**
+ * Returns a shallow copy of the given array suffixed by "suffix"
+ * null items.
+ */
+ public static Symbol[] cloneArray(Symbol[] array, int suffix) {
+ return cloneArray(0, array, suffix);
+ }
+
+ /**
+ * Returns a shallow copy of the given array prefixed by "prefix"
+ * null items and suffixed by "suffix" null items.
+ */
+ public static Symbol[] cloneArray(int prefix, Symbol[] array, int suffix) {
+ assert prefix >= 0 && suffix >= 0: prefix + " - " + suffix;
+ int size = prefix + array.length + suffix;
+ if (size == 0) return EMPTY_ARRAY;
+ Symbol[] clone = new Symbol[size];
+ for (int i = 0; i < array.length; i++) clone[prefix + i] = array[i];
return clone;
}
diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java
index 7d771b927d..38ae8d8613 100644
--- a/sources/scalac/symtab/Type.java
+++ b/sources/scalac/symtab/Type.java
@@ -1305,9 +1305,35 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags {
/** Returns a shallow copy of the given array. */
public static Type[] cloneArray(Type[] array) {
- if (array.length == 0) return array;
- Type[] clone = new Type[array.length];
- for (int i = 0; i < clone.length; i++) clone[i] = array[i];
+ return cloneArray(0, array, 0);
+ }
+
+ /**
+ * Returns a shallow copy of the given array prefixed by "prefix"
+ * null items.
+ */
+ public static Type[] cloneArray(int prefix, Type[] array) {
+ return cloneArray(prefix, array, 0);
+ }
+
+ /**
+ * Returns a shallow copy of the given array suffixed by "suffix"
+ * null items.
+ */
+ public static Type[] cloneArray(Type[] array, int suffix) {
+ return cloneArray(0, array, suffix);
+ }
+
+ /**
+ * Returns a shallow copy of the given array prefixed by "prefix"
+ * null items and suffixed by "suffix" null items.
+ */
+ public static Type[] cloneArray(int prefix, Type[] array, int suffix) {
+ assert prefix >= 0 && suffix >= 0: prefix + " - " + suffix;
+ int size = prefix + array.length + suffix;
+ if (size == 0) return EMPTY_ARRAY;
+ Type[] clone = new Type[size];
+ for (int i = 0; i < array.length; i++) clone[prefix + i] = array[i];
return clone;
}