diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso index 6cbcbd58adf65..01a9f20878157 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso @@ -601,8 +601,11 @@ type Vector + : Vector Any -> Vector Any + that = this_len = this.length - arr = Array.clone this.to_array 0 this_len (this_len + that.length) - Array.copy that.to_array 0 arr this_len that.length + arr = Array.new (this_len + that.length) + 0.up_to this_len . each i-> + arr.set_at i (this.unsafe_at i) + this.length.up_to arr.length . each i-> + arr.set_at i (that.unsafe_at i-this_len) Vector arr ## Add `element` to the beginning of `this` vector. @@ -664,7 +667,7 @@ type Vector slice_end = Math.min this.length end if slice_start >= slice_end then Vector (Array.new 0) else len = slice_end - slice_start - new_array = Array.clone this.to_array slice_start len len + here.new len (i -> this.unsafe_at (i+slice_start)) Vector new_array ## Creates a new vector with the first `count` elements in `this` removed. @@ -893,7 +896,8 @@ type Vector ## Prepare the destination array that will underlie the vector. We do not want to sort in place on the original vector, as `sort` is not intended to be mutable. - new_vec_arr = Array.clone this.to_array 0 this.length this.length + new_vec_arr = Array.new this.length + Array.copy this.to_array 0 new_vec_arr 0 this.length ## As we want to account for both custom projections and custom comparisons we need to construct a comparator for internal use that @@ -1068,7 +1072,8 @@ type Builder Unsafe.set_atom_field this 1 (this.length + 1) False -> old_array = this.to_array - new_array = Array.clone this.to_array 0 old_array.length old_array.length*2 + new_array = Array.new old_array.length*2 + Array.copy old_arrays 0 new_array 0 old_array.length Unsafe.set_atom_field this 0 new_array this.append item Nothing @@ -1096,7 +1101,9 @@ type Builder bldr.to_vector to_vector : Vector Any to_vector = - new_array = Array.clone this.to_array 0 this.length this.length + old_array = this.to_array + new_array = Array.new this.length + Array.copy old_arrays 0 new_array 0 this.length Vector new_array ## UNSTABLE diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/mutable/CloneNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/mutable/CloneNode.java deleted file mode 100644 index f25567ed2866e..0000000000000 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/mutable/CloneNode.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.enso.interpreter.node.expression.builtin.mutable; - -import com.oracle.truffle.api.dsl.CachedContext; -import com.oracle.truffle.api.dsl.Fallback; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.interop.InteropLibrary; -import com.oracle.truffle.api.interop.InvalidArrayIndexException; -import com.oracle.truffle.api.interop.UnsupportedMessageException; -import com.oracle.truffle.api.library.CachedLibrary; -import com.oracle.truffle.api.nodes.Node; -import org.enso.interpreter.Language; -import org.enso.interpreter.dsl.BuiltinMethod; -import org.enso.interpreter.runtime.Context; -import org.enso.interpreter.runtime.builtin.Builtins; -import org.enso.interpreter.runtime.data.Array; -import org.enso.interpreter.runtime.error.PanicException; - -@BuiltinMethod(type = "Array", name = "clone", description = "Copies one array to another.") -public abstract class CloneNode extends Node { - - static CloneNode build() { - return CloneNodeGen.create(); - } - - abstract Object execute( - Object _this, Object src, long source_index, long source_count, long new_size); - - @Specialization - Object doArray( - Object _this, - Array src, - long source_index, - long source_count, - long new_size, - @CachedContext(Language.class) Context ctx) { - Array output = new Array(new_size); - System.arraycopy( - src.getItems(), (int) source_index, output.getItems(), 0, (int) source_count); - return output; - } - - @Specialization - Object doPolyglotArray( - Object _this, - byte[] src, - long source_index, - long source_count, - long new_size, - @CachedContext(Language.class) Context ctx) { - byte[] output = new byte[(int) new_size]; - System.arraycopy(src, (int) source_index, output, 0, (int) source_count); - return output; - } - - @Specialization - Object doPolyglotArray( - Object _this, - int[] src, - long source_index, - long source_count, - long new_size, - @CachedContext(Language.class) Context ctx) { - int[] output = new int[(int) new_size]; - System.arraycopy(src, (int) source_index, output, 0, (int) source_count); - return output; - } - - @Specialization - Object doPolyglotArray( - Object _this, - long[] src, - long source_index, - long source_count, - long new_size, - @CachedContext(Language.class) Context ctx) { - long[] output = new long[(int) new_size]; - System.arraycopy(src, (int) source_index, output, 0, (int) source_count); - return output; - } - - @Specialization - Object doPolyglotArray( - Object _this, - char[] src, - long source_index, - long source_count, - long new_size, - @CachedContext(Language.class) Context ctx) { - char[] output = new char[(int) new_size]; - System.arraycopy(src, (int) source_index, output, 0, (int) source_count); - return output; - } - - @Specialization - Object doPolyglotArray( - Object _this, - float[] src, - long source_index, - long source_count, - long new_size, - @CachedContext(Language.class) Context ctx) { - float[] output = new float[(int) new_size]; - System.arraycopy(src, (int) source_index, output, 0, (int) source_count); - return output; - } - - @Specialization - Object doPolyglotArray( - Object _this, - double[] src, - long source_index, - long new_size, - long source_count, - @CachedContext(Language.class) Context ctx) { - double[] output = new double[(int) new_size]; - System.arraycopy(src, (int) source_index, output, 0, (int) source_count); - return output; - } - - @Specialization(guards = "arrays.hasArrayElements(src)") - Object doPolyglotArray( - Object _this, - Object src, - long source_index, - long new_size, - long source_count, - @CachedLibrary(limit = "3") InteropLibrary arrays, - @CachedContext(Language.class) Context ctx) { - Array dest = new Array(new_size); - try { - for (int i = 0; i < source_count; i++) { - dest.getItems()[i] = arrays.readArrayElement(src, source_index + i); - } - } catch (UnsupportedMessageException e) { - throw new IllegalStateException("Unreachable"); - } catch (InvalidArrayIndexException e) { - throw new PanicException( - ctx.getBuiltins().error().makeInvalidArrayIndexError(src, e.getInvalidIndex()), this); - } - return dest; - } - - @Fallback - Object doOther( - Object _this, - Object src, - long source_index, - long source_count, - long new_size) { - Builtins builtins = lookupContextReference(Language.class).get().getBuiltins(); - throw new PanicException( - builtins.error().makeTypeError(builtins.mutable().array().newInstance(), src, "src"), this); - } -} \ No newline at end of file diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Mutable.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Mutable.java index a7ab5cd8c5819..3e055e01e2284 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Mutable.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Mutable.java @@ -30,7 +30,6 @@ public Mutable(Language language, ModuleScope scope) { scope.registerMethod(array, "at", GetAtMethodGen.makeFunction(language)); scope.registerMethod(array, "set_at", SetAtMethodGen.makeFunction(language)); scope.registerMethod(array, "copy", CopyMethodGen.makeFunction(language)); - scope.registerMethod(array, "clone", CloneMethodGen.makeFunction(language)); scope.registerMethod(array, "sort", SortMethodGen.makeFunction(language)); ref = new AtomConstructor("Ref", scope).initializeFields(); diff --git a/engine/runtime/src/main/resources/Builtins.enso b/engine/runtime/src/main/resources/Builtins.enso index 92aaf9390d34d..8f2bfcfa59162 100644 --- a/engine/runtime/src/main/resources/Builtins.enso +++ b/engine/runtime/src/main/resources/Builtins.enso @@ -906,19 +906,6 @@ type Array copy src source_index dest dest_index count = @Builtin_Method "Array.copy" - ## Clones from the source array, beginning at the specified position, to - a new destination array. - - Arguments: - - src: The source array. - - source_index: The start position in the src array. - - source_count: Amount to copy from source. - - new_size: Size of new array. - - clone : Array -> Integer -> Integer -> Integer -> Array - clone src source_index source_count new_size = - @Builtin_Method "Array.clone" - ## Gets the element at index in the array this. Arguments: