Skip to content

Commit

Permalink
Allow slice to be whole Vector and then avoid copies for builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley authored and hubertp committed Oct 4, 2022
1 parent b948910 commit f732be7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
8 changes: 4 additions & 4 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 @@ -1085,10 +1085,10 @@ type Builder
bldr.to_vector
to_vector : Vector Any
to_vector self =
## This creates a fresh copy of the builders storage, so any future
changes to the builder will not affect the returned vector.
new_array = self.java_builder.toArray
from_polyglot_array new_array
## The slice means that if the builder is appended to later, the
returned vector remains unchanged.
list = self.java_builder.asList
from_polyglot_array list . slice 0 list.size

## UNSTABLE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ public final Vector slice(long start, long end, InteropLibrary interop)
return new Vector(new Array(0));
}

if ((slice_start == 0) && (slice_end == this_length)) {
return this;
}

return new Vector(new ArraySlice(this.storage, slice_start, slice_end));
}

Expand Down
6 changes: 2 additions & 4 deletions std-bits/base/src/main/java/org/enso/base/Array_Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public void appendTo(List<T> list) {
builder.addAll(list);
}

/** Converts current content to a new array. */
public Object[] toArray() {
return builder.toArray();
}
/** Gets the backing store of the Builder as a List */
public List<T> asList() { return builder; }
}

0 comments on commit f732be7

Please sign in to comment.