Skip to content

Commit 5d38f2d

Browse files
committed
Code cleanup.
1 parent 93d69b8 commit 5d38f2d

13 files changed

+29
-22
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,6 @@ public BuilderState start(int length) {
178178
return new BuilderState(allocator.allocate(length), length);
179179
}
180180
}
181-
182-
public BuilderState share(BuilderState state) {
183-
return state;
184-
}
185181
}
186182

187183
@ImportStatic(ArrayGuards.class)

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ protected void noop(Object dstStore, Object srcStore, int dstStart, int srcStart
5252
guards = "!noopGuard(dstStore, srcStore, dstStart, srcStart, length)",
5353
limit = "storageStrategyLimit()")
5454
protected void copy(Object dstStore, Object srcStore, int dstStart, int srcStart, int length,
55-
@CachedLibrary("srcStore") ArrayStoreLibrary stores,
56-
@Cached WriteBarrierNode writeBarrierNode,
57-
@Cached ConditionProfile share,
58-
@Cached LoopConditionProfile loopProfile) {
55+
@CachedLibrary("srcStore") ArrayStoreLibrary stores) {
5956

6057
stores.copyContents(srcStore, srcStart, dstStore, dstStart, length);
6158
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.truffleruby.core.array;
1111

1212
import org.truffleruby.RubyLanguage;
13+
import org.truffleruby.core.array.library.ZeroLengthArrayStore;
1314

1415
public class ArrayGuards {
1516

@@ -36,4 +37,8 @@ public static boolean basicStore(Object store) {
3637
return store instanceof int[] || store instanceof long[] || store instanceof double[] ||
3738
store instanceof Object[];
3839
}
40+
41+
public static boolean zeroLengthStore(Object store) {
42+
return store == ZeroLengthArrayStore.ZERO_LENGTH_STORE;
43+
}
3944
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,8 @@ protected abstract RubyArray executeInitialize(RubyArray array, Object size, Obj
11721172
protected RubyArray initializeNoArgs(RubyArray array, NotProvided size, NotProvided fillingValue, Nil block,
11731173
@Cached IsSharedNode isSharedNode,
11741174
@Cached ConditionProfile sharedProfile) {
1175-
setStoreAndSize(array, ArrayStoreLibrary.initialStorage(sharedProfile.profile(isSharedNode.executeIsShared(array))), 0);
1175+
setStoreAndSize(array,
1176+
ArrayStoreLibrary.initialStorage(sharedProfile.profile(isSharedNode.executeIsShared(array))), 0);
11761177
return array;
11771178
}
11781179

@@ -1181,7 +1182,8 @@ protected RubyArray initializeOnlyBlock(
11811182
RubyArray array, NotProvided size, NotProvided fillingValue, RubyProc block,
11821183
@Cached IsSharedNode isShared,
11831184
@Cached ConditionProfile sharedProfile) {
1184-
setStoreAndSize(array, ArrayStoreLibrary.initialStorage(sharedProfile.profile(isShared.executeIsShared(array))), 0);
1185+
setStoreAndSize(array,
1186+
ArrayStoreLibrary.initialStorage(sharedProfile.profile(isShared.executeIsShared(array))), 0);
11851187
return array;
11861188
}
11871189

src/main/java/org/truffleruby/core/array/library/ArrayStoreLibrary.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static ArrayAllocator initialAllocator(boolean shared) {
105105
/** Return whether {@code store} and {@code other} share the same underlying array storage. */
106106
public abstract boolean isSameStorage(Object store, Object other);
107107

108-
/** Return the underlying storage used by this array, which may be behind multiple warppers. Stores which wrap some
108+
/** Return the underlying storage used by this array, which may be behind multiple wrappers. Stores which wrap some
109109
* array store should always recursively unwrap that store using this same library call. */
110110
public Object backingStore(Object store) {
111111
return store;
@@ -154,7 +154,7 @@ public Object extractRange(Object store, int start, int end) {
154154
* elements, so that that range does not retain references to objects/memory/resources. This can be understood as
155155
* "nulling out" that part of the array, and will do nothing for primitive arrays. */
156156
public void clear(Object store, int start, int length) {
157-
throw CompilerDirectives.shouldNotReachHere();
157+
throw new UnsupportedOperationException("clear operation not supported");
158158
}
159159

160160
/** Fill the part of the array starting at {@code start} and extending for {@code length} elements using

src/main/java/org/truffleruby/core/array/library/DelegatedArrayStorage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ public DelegatedArrayStorage(Object storage, int offset, int length) {
211211
assert offset >= 0;
212212
assert length >= 0;
213213
assert !(storage instanceof DelegatedArrayStorage);
214+
assert !(storage instanceof NativeArrayStorage);
215+
assert !(storage instanceof SharedArrayStorage);
214216
this.storage = storage;
215217
this.offset = offset;
216218
this.length = length;

src/main/java/org/truffleruby/core/array/library/DoubleArrayStore.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected static boolean acceptsDelegateValues(double[] store, DelegatedArraySto
6464
}
6565

6666
@Specialization
67-
protected static boolean acceptsDelegateValues(double[] store, SharedArrayStorage otherStore,
67+
protected static boolean acceptsSharedValues(double[] store, SharedArrayStorage otherStore,
6868
@CachedLibrary("store") ArrayStoreLibrary stores) {
6969
return stores.acceptsAllValues(store, otherStore.storage);
7070
}
@@ -310,7 +310,8 @@ protected static Object allocate(double[] store, Object[] newStore, int length)
310310
return ObjectArrayStore.OBJECT_ARRAY_ALLOCATOR.allocate(length);
311311
}
312312

313-
@Specialization(guards = "!basicStore(newStore)", limit = "storageStrategyLimit()")
313+
@Specialization(guards = { "!basicStore(newStore)", "!zeroLengthStore(newStore)" },
314+
limit = "storageStrategyLimit()")
314315
protected static Object allocate(double[] store, Object newStore, int length,
315316
@CachedLibrary("newStore") ArrayStoreLibrary newStores) {
316317
return newStores.allocateForNewStore(newStore, store, length);

src/main/java/org/truffleruby/core/array/library/IntegerArrayStore.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected static boolean acceptsDelegateValues(int[] store, DelegatedArrayStorag
6464
}
6565

6666
@Specialization
67-
protected static boolean acceptsDelegateValues(int[] store, SharedArrayStorage otherStore,
67+
protected static boolean acceptsSharedValues(int[] store, SharedArrayStorage otherStore,
6868
@CachedLibrary("store") ArrayStoreLibrary stores) {
6969
return stores.acceptsAllValues(store, otherStore.storage);
7070
}
@@ -330,7 +330,8 @@ protected static Object allocate(int[] store, Object[] newStore, int length) {
330330
return ObjectArrayStore.OBJECT_ARRAY_ALLOCATOR.allocate(length);
331331
}
332332

333-
@Specialization(guards = "!basicStore(newStore)", limit = "storageStrategyLimit()")
333+
@Specialization(guards = { "!basicStore(newStore)", "!zeroLengthStore(newStore)" },
334+
limit = "storageStrategyLimit()")
334335
protected static Object allocate(int[] store, Object newStore, int length,
335336
@CachedLibrary("newStore") ArrayStoreLibrary newStores) {
336337
return newStores.allocateForNewStore(newStore, store, length);

src/main/java/org/truffleruby/core/array/library/LongArrayStore.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected static boolean acceptsDelegateValues(long[] store, DelegatedArrayStora
6969
}
7070

7171
@Specialization
72-
protected static boolean acceptsDelegateValues(long[] store, SharedArrayStorage otherStore,
72+
protected static boolean acceptsSharedValues(long[] store, SharedArrayStorage otherStore,
7373
@CachedLibrary("store") ArrayStoreLibrary stores) {
7474
return stores.acceptsAllValues(store, otherStore.storage);
7575
}
@@ -350,7 +350,8 @@ protected static Object allocate(long[] store, Object[] newStore, int length) {
350350
return ObjectArrayStore.OBJECT_ARRAY_ALLOCATOR.allocate(length);
351351
}
352352

353-
@Specialization(guards = "!basicStore(newStore)", limit = "storageStrategyLimit()")
353+
@Specialization(guards = { "!basicStore(newStore)", "!zeroLengthStore(newStore)" },
354+
limit = "storageStrategyLimit()")
354355
protected static Object allocate(long[] store, Object newStore, int length,
355356
@CachedLibrary("newStore") ArrayStoreLibrary newStores) {
356357
return newStores.allocateForNewValue(newStore, store, length);

src/main/java/org/truffleruby/core/array/library/NativeArrayStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ protected static void shareElements(NativeArrayStorage store,
187187
@Cached WriteBarrierNode writeBarrierNode) {
188188
int i = 0;
189189
try {
190-
for (; i < store.length; i++) {
190+
for (; loopProfile.inject(i < store.length); i++) {
191191
writeBarrierNode.executeWriteBarrier(node.read(store, i));
192192
}
193193
} finally {

0 commit comments

Comments
 (0)