Skip to content

Commit 0f0b3af

Browse files
author
Nicolas Laurent
committed
refactor uses of ArrayHelpers#createArray than can be fixed using local variables or RubyContext[Source]Node methods
1 parent b3e7c1d commit 0f0b3af

17 files changed

+30
-41
lines changed

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.jcodings.specific.USASCIIEncoding;
1919
import org.jcodings.specific.UTF8Encoding;
2020
import org.truffleruby.Layouts;
21-
import org.truffleruby.RubyLanguage;
2221
import org.truffleruby.builtins.CoreMethod;
2322
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
2423
import org.truffleruby.builtins.CoreMethodNode;
@@ -31,7 +30,6 @@
3130
import org.truffleruby.core.CoreLibrary;
3231
import org.truffleruby.core.MarkingService.ExtensionCallStack;
3332
import org.truffleruby.core.MarkingServiceNodes;
34-
import org.truffleruby.core.array.ArrayHelpers;
3533
import org.truffleruby.core.array.ArrayToObjectArrayNode;
3634
import org.truffleruby.core.array.RubyArray;
3735
import org.truffleruby.core.encoding.RubyEncoding;
@@ -358,7 +356,7 @@ private RubyArray bytes(BigInteger bi, int num_words, int word_length, boolean m
358356
}
359357
}
360358
}
361-
return ArrayHelpers.createArray(getContext(), bytes);
359+
return createArray(bytes);
362360
}
363361

364362

src/main/java/org/truffleruby/core/array/ArrayConvertNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static ArrayConvertNode create() {
2828
public RubyArray execute(Object object) {
2929
Object converted = arrayCast.execute(object);
3030
if (cantCast.profile(converted == nil)) {
31-
return ArrayHelpers.specializedRubyArrayOf(getContext(), arrayBuilder, object);
31+
return ArrayHelpers.specializedRubyArrayOf(getContext(), getLanguage(), arrayBuilder, object);
3232
}
3333
return (RubyArray) converted;
3434
}

src/main/java/org/truffleruby/core/array/ArrayDropTailNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected RubyArray dropTail(RubyArray array,
3737
@Cached ConditionProfile indexLargerThanSize) {
3838
final int size = array.size;
3939
if (indexLargerThanSize.profile(index >= size)) {
40-
return ArrayHelpers.createEmptyArray(getContext());
40+
return createEmptyArray();
4141
} else {
4242
final int newSize = size - index;
4343
final Object withoutTail = cowNode.execute(array, 0, newSize);

src/main/java/org/truffleruby/core/array/ArrayDupNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected RubyArray dup(RubyArray from,
6363
}
6464

6565
private RubyArray allocateArray(RubyClass rubyClass, Object store, int size) {
66-
RubyArray array = new RubyArray(rubyClass, RubyLanguage.arrayShape, store, size);
66+
RubyArray array = new RubyArray(rubyClass, getLanguage().arrayShape, store, size);
6767
AllocationTracing.trace(array, this);
6868
return array;
6969
}

src/main/java/org/truffleruby/core/array/ArrayGetTailNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected RubyArray getTail(RubyArray array,
3737
@Cached ConditionProfile indexLargerThanSize) {
3838
final int size = array.size;
3939
if (indexLargerThanSize.profile(index >= size)) {
40-
return ArrayHelpers.createEmptyArray(getContext());
40+
return createEmptyArray();
4141
} else {
4242
final Object newStore = cowNode.execute(array, index, size - index);
4343
return createArray(newStore, size - index);

src/main/java/org/truffleruby/core/array/ArrayLiteralNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected RubyArray makeGeneric(VirtualFrame frame, Object[] alreadyExecuted) {
5454
}
5555

5656
protected RubyArray cachedCreateArray(Object store, int size) {
57-
final RubyArray array = new RubyArray(coreLibrary().arrayClass, RubyLanguage.arrayShape, store, size);
57+
final RubyArray array = createArray(store, size);
5858
AllocationTracing.trace(array, this);
5959
return array;
6060
}

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,13 +1621,13 @@ protected Object popNNegative(RubyArray array, int n) {
16211621
@Specialization(guards = { "n >= 0", "isEmptyArray(array)" })
16221622
@ReportPolymorphism.Exclude
16231623
protected RubyArray popEmpty(RubyArray array, int n) {
1624-
return ArrayHelpers.createEmptyArray(getContext());
1624+
return createEmptyArray();
16251625
}
16261626

16271627
@Specialization(guards = { "n == 0", "!isEmptyArray(array)" })
16281628
@ReportPolymorphism.Exclude
16291629
protected RubyArray popZeroNotEmpty(RubyArray array, int n) {
1630-
return ArrayHelpers.createEmptyArray(getContext());
1630+
return createEmptyArray();
16311631
}
16321632

16331633
@Specialization(
@@ -2076,12 +2076,12 @@ protected Object shiftNegative(RubyArray array, int n) {
20762076

20772077
@Specialization(guards = "n == 0")
20782078
protected Object shiftZero(RubyArray array, int n) {
2079-
return ArrayHelpers.createEmptyArray(getContext());
2079+
return createEmptyArray();
20802080
}
20812081

20822082
@Specialization(guards = { "n > 0", "isEmptyArray(array)" })
20832083
protected Object shiftManyEmpty(RubyArray array, int n) {
2084-
return ArrayHelpers.createEmptyArray(getContext());
2084+
return createEmptyArray();
20852085
}
20862086

20872087
@Specialization(
@@ -2125,7 +2125,7 @@ public abstract static class SortNode extends ArrayCoreMethodNode {
21252125
@Specialization(guards = "isEmptyArray(array)")
21262126
@ReportPolymorphism.Exclude
21272127
protected RubyArray sortEmpty(RubyArray array, Object unusedBlock) {
2128-
return ArrayHelpers.createEmptyArray(getContext());
2128+
return createEmptyArray();
21292129
}
21302130

21312131
@ExplodeLoop

src/main/java/org/truffleruby/core/array/ArraySliceNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected RubyArray readInBounds(RubyArray array,
3939
final int length = array.size + to - from;
4040

4141
if (emptyArray.profile(length <= 0)) {
42-
return ArrayHelpers.createEmptyArray(getContext());
42+
return createEmptyArray();
4343
} else {
4444
final Object slice = cowNode.execute(array, from, length);
4545
return createArray(slice, length);

src/main/java/org/truffleruby/core/cast/ArrayCastNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
package org.truffleruby.core.cast;
1111

12-
import org.truffleruby.core.array.ArrayHelpers;
1312
import org.truffleruby.core.array.RubyArray;
1413
import org.truffleruby.core.numeric.RubyBignum;
1514
import org.truffleruby.language.Nil;
@@ -90,7 +89,7 @@ protected RubyArray castArray(RubyArray array) {
9089
protected Object cast(Nil nil) {
9190
switch (nilBehavior) {
9291
case EMPTY_ARRAY:
93-
return ArrayHelpers.createEmptyArray(getContext());
92+
return createEmptyArray();
9493

9594
case ARRAY_WITH_NIL:
9695
return createArray(new Object[]{ nil });

src/main/java/org/truffleruby/core/cast/SplatCastNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.truffleruby.RubyLanguage;
1313
import org.truffleruby.core.array.ArrayDupNode;
1414
import org.truffleruby.core.array.ArrayDupNodeGen;
15-
import org.truffleruby.core.array.ArrayHelpers;
1615
import org.truffleruby.core.array.RubyArray;
1716
import org.truffleruby.core.symbol.RubySymbol;
1817
import org.truffleruby.language.Nil;
@@ -63,7 +62,7 @@ public void doNotCopy() {
6362
protected Object splatNil(VirtualFrame frame, Nil nil) {
6463
switch (nilBehavior) {
6564
case EMPTY_ARRAY:
66-
return ArrayHelpers.createEmptyArray(getContext());
65+
return createEmptyArray();
6766

6867
case ARRAY_WITH_NIL:
6968
return createArray(new Object[]{ nil });

0 commit comments

Comments
 (0)