Skip to content

Commit

Permalink
Move to static method
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley committed Mar 3, 2022
1 parent 83661f1 commit b2a3b0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all
from Standard.Builtins import Builtins

## UNSTABLE
ADVANCED
Expand All @@ -17,3 +18,12 @@ Array.to_default_visualization_data : Text
Array.to_default_visualization_data =
Vector.Vector this . to_default_visualization_data

## PRIVATE
Copy the backing Array to an Enso Array
TODO This is a workaround for the issue with polyglot Array.copy
https://www.pivotaltracker.com/story/show/181122542
Array.copy_to : Array->Integer->Array->Integer->Integer
Array.copy_to src_array src_start dest_array dest_start length =
case Builtins.Meta.is_polyglot src_array of
True -> 0.up_to length . each i->(dest_array.set_at (i+dest_start) (src_array.at i+src_start))
False -> Array.copy src_array src_start dest_array dest_start length
20 changes: 5 additions & 15 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ type Vector
length = this.fold 0 acc-> elem-> acc + elem.length
arr = Array.new length
this.fold 0 i-> vec->
vec.copy_array 0 arr i vec.length
Array.copy_to vec.to_array 0 arr i vec.length
i + vec.length
Vector arr

Expand Down Expand Up @@ -581,16 +581,6 @@ type Vector
eq_at i = this.unsafe_at i == that.unsafe_at i
if this.length == that.length then 0.up_to this.length . all eq_at else False

## PRIVATE
Copy the backing Array to an Enso Array
TODO This is a workaround for the issue with polyglot Array.copy
https://www.pivotaltracker.com/story/show/181122542
copy_array : Array
copy_array start_index dest_array dest_start length =
case Builtins.Meta.is_polyglot this.to_array of
True -> 0.up_to length . each i->(dest_array.set_at (i+dest_start) (this.to_array.at i+start_index))
False -> Array.copy this.to_array start_index dest_array dest_start length

## Concatenates two vectors, resulting in a new vector, containing all the
elements of `this`, followed by all the elements of `that`.

Expand All @@ -605,8 +595,8 @@ type Vector
+ that =
this_len = this.length
arr = Array.new (this_len + that.length)
this.copy_array 0 arr 0 this_len
that.copy_array 0 arr this_len that.length
Array.copy_to this.to_array 0 arr 0 this_len
Array.copy_to that.to_array 0 arr this_len that.length
Vector arr

## Add `element` to the beginning of `this` vector.
Expand Down Expand Up @@ -670,7 +660,7 @@ type Vector
if (slice_start == 0) && (slice_end == this.length) then this else
len = slice_end - slice_start
arr = Array.new len
this.copy_array slice_start arr 0 len
Array.copy_to this.to_array slice_start arr 0 len
Vector arr

## Creates a new vector with the first `count` elements in `this` removed.
Expand Down Expand Up @@ -900,7 +890,7 @@ type Vector
not want to sort in place on the original vector, as `sort` is not
intended to be mutable.
new_vec_arr = Array.new this.length
this.copy_array 0 new_vec_arr 0 this.length
Array.copy_to 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
Expand Down

0 comments on commit b2a3b0d

Please sign in to comment.