Skip to content

Commit

Permalink
Explicitly call Array.allocate(int)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Feb 22, 2023
1 parent bfb5a61 commit bb03d51
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Array execute() {
public static Array stackTraceToArray(Throwable exception) {
var elements = TruffleStackTrace.getStackTrace(exception);
if (elements == null) return new Array();
var ret = new Array(elements.size());
var ret = Array.allocate(elements.size());
for (int i = 0; i < elements.size(); i++) {
var element = elements.get(i);
ret.getItems()[i] = element.getGuestObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public boolean hasMembers() {
public Array getMembers(boolean includeInternal) {
Map<String, Function> members = constructor.getDefinitionScope().getMethods().get(constructor.getType());
if (members == null) {
return new Array(0);
return Array.allocate(0);
}
Object[] mems = members.keySet().toArray();
return new Array(mems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public Array(Object... items) {
*/
@Builtin.Method(
description = "Creates an uninitialized array of a given size.",
autoRegister = false, name = "new")
public static Array empty(long size) {
autoRegister = false,
name = "new")
public static Array allocate(long size) {
var arr = new Object[(int) size];
var ctx = EnsoContext.get(null);
var nothing = ctx.getBuiltins().nothing();
Expand Down Expand Up @@ -123,7 +124,7 @@ public long length() {
/** @return an empty array */
@Builtin.Method(description = "Creates an empty Array", autoRegister = false)
public static Object empty() {
return new Array();
return allocate(0);
}

/** @return an identity array */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public final Vector slice(long start, long end, InteropLibrary interop)
long slice_end = Math.min(this_length, end);

if (slice_start >= slice_end) {
return new Vector(new Array(0));
return new Vector(Array.allocate(0));
}

if ((slice_start == 0) && (slice_end == this_length)) {
Expand Down

0 comments on commit bb03d51

Please sign in to comment.