Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: db093e83fc90
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 61212e845e44
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on Apr 19, 2016

  1. Copy the full SHA
    148504b View commit details
  2. Copy the full SHA
    2f65483 View commit details
  3. Copy the full SHA
    61212e8 View commit details
Showing with 50 additions and 174 deletions.
  1. +50 −174 truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
224 changes: 50 additions & 174 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -1006,9 +1006,7 @@ public DynamicObject initializeFromArray(DynamicObject array, DynamicObject copy
}

@Specialization(guards = { "!isInteger(object)", "!isLong(object)", "wasProvided(object)", "!isRubyArray(object)" })
public DynamicObject initialize(VirtualFrame frame, DynamicObject array, Object object, NotProvided defaultValue, NotProvided block,
@Cached("createReplaceNode()") ReplaceNode replaceNode) {

public DynamicObject initialize(VirtualFrame frame, DynamicObject array, Object object, NotProvided defaultValue, NotProvided block) {
DynamicObject copy = null;
if (respondToToAry(frame, object)) {
Object toAryResult = callToAry(frame, object);
@@ -1067,58 +1065,23 @@ public abstract static class InitializeCopyNode extends CoreMethodNode {
return ToAryNodeGen.create(null, null, other);
}

@Specialization(guards = {"isRubyArray(from)", "isNullArray(from)"})
public DynamicObject initializeCopyNull(DynamicObject self, DynamicObject from) {
if (self == from) {
return self;
}
setStoreAndSize(self, null, 0);
return self;
}

@Specialization(guards = {"isRubyArray(from)", "isIntArray(from)"})
public DynamicObject initializeCopyIntegerFixnum(DynamicObject self, DynamicObject from) {
if (self == from) {
return self;
}
final int[] store = (int[]) getStore(from);
setStoreAndSize(self, store.clone(), getSize(from));
return self;
}

@Specialization(guards = {"isRubyArray(from)", "isLongArray(from)"})
public DynamicObject initializeCopyLongFixnum(DynamicObject self, DynamicObject from) {
if (self == from) {
return self;
}
final long[] store = (long[]) getStore(from);
setStoreAndSize(self, store.clone(), getSize(from));
return self;
}

@Specialization(guards = {"isRubyArray(from)", "isDoubleArray(from)"})
public DynamicObject initializeCopyFloat(DynamicObject self, DynamicObject from) {
@Specialization
public DynamicObject initializeCopy(DynamicObject self, DynamicObject from,
@Cached("createReplaceNode()") ReplaceNode replaceNode) {
if (self == from) {
return self;
}
final double[] store = (double[]) getStore(from);
setStoreAndSize(self, store.clone(), getSize(from));
replaceNode.executeReplace(self, from);
return self;
}

@Specialization(guards = {"isRubyArray(from)", "isObjectArray(from)"})
public DynamicObject initializeCopyObject(DynamicObject self, DynamicObject from) {
if (self == from) {
return self;
}
final Object[] store = (Object[]) getStore(from);
setStoreAndSize(self, ArrayUtils.copy(store), getSize(from));
return self;
protected ReplaceNode createReplaceNode() {
return ReplaceNodeFactory.create(null, null);
}

}

@CoreMethod(names = {"inject", "reduce"}, needsBlock = true, optional = 2)
@CoreMethod(names = { "inject", "reduce" }, needsBlock = true, optional = 2)
@ImportStatic(ArrayGuards.class)
public abstract static class InjectNode extends YieldingCoreMethodNode {

@@ -1129,6 +1092,8 @@ public InjectNode(RubyContext context, SourceSection sourceSection) {
dispatch = DispatchHeadNodeFactory.createMethodCall(context, MissingBehavior.CALL_METHOD_MISSING);
}

// With block

@Specialization(guards = { "isEmptyArray(array)", "wasProvided(initial)" })
public Object injectEmptyArray(VirtualFrame frame, DynamicObject array, Object initial, NotProvided unused, DynamicObject block) {
return initial;
@@ -1139,164 +1104,75 @@ public Object injectEmptyArrayNoInitial(VirtualFrame frame, DynamicObject array,
return nil();
}

@Specialization(guards = { "isIntArray(array)", "!isEmptyArray(array)", "wasProvided(initial)" })
public Object injectIntegerFixnum(VirtualFrame frame, DynamicObject array, Object initial, NotProvided unused, DynamicObject block) {
return injectHelper(frame, ArrayReflector.reflect((int[]) getStore(array)), array, initial, block, 0);
}

@Specialization(guards = { "isIntArray(array)", "!isEmptyArray(array)" })
public Object injectIntegerFixnumNoInitial(VirtualFrame frame, DynamicObject array, NotProvided initial, NotProvided unused, DynamicObject block) {
final ArrayMirror mirror = ArrayReflector.reflect((int[]) getStore(array));

return injectHelper(frame, mirror, array, mirror.get(0), block, 1);
}

@Specialization(guards = { "isLongArray(array)", "!isEmptyArray(array)", "wasProvided(initial)" })
public Object injectLongFixnum(VirtualFrame frame, DynamicObject array, Object initial, NotProvided unused, DynamicObject block) {
return injectHelper(frame, ArrayReflector.reflect((long[]) getStore(array)), array, initial, block, 0);
}

@Specialization(guards = { "isLongArray(array)", "!isEmptyArray(array)" })
public Object injectLongFixnumNoInitial(VirtualFrame frame, DynamicObject array, NotProvided initial, NotProvided unused, DynamicObject block) {
final ArrayMirror mirror = ArrayReflector.reflect((long[]) getStore(array));

return injectHelper(frame, mirror, array, mirror.get(0), block, 1);
}

@Specialization(guards = { "isDoubleArray(array)", "!isEmptyArray(array)", "wasProvided(initial)" })
public Object injectFloat(VirtualFrame frame, DynamicObject array, Object initial, NotProvided unused, DynamicObject block) {
return injectHelper(frame, ArrayReflector.reflect((double[]) getStore(array)), array, initial, block, 0);
}

@Specialization(guards = { "isDoubleArray(array)", "!isEmptyArray(array)" })
public Object injectFloatNoInitial(VirtualFrame frame, DynamicObject array, NotProvided initial, NotProvided unused, DynamicObject block) {
final ArrayMirror mirror = ArrayReflector.reflect((double[]) getStore(array));

return injectHelper(frame, mirror, array, mirror.get(0), block, 1);
@Specialization(guards = { "strategy.matches(array)", "!isEmptyArray(array)", "wasProvided(initial)" }, limit = "ARRAY_STRATEGIES")
public Object injectWithInitial(VirtualFrame frame, DynamicObject array, Object initial, NotProvided unused, DynamicObject block,
@Cached("of(array)") ArrayStrategy strategy) {
final ArrayMirror store = strategy.newMirror(array);
return injectBlockHelper(frame, array, block, store, initial, 0);
}

@Specialization(guards = { "isObjectArray(array)", "!isEmptyArray(array)", "wasProvided(initial)" })
public Object injectObject(VirtualFrame frame, DynamicObject array, Object initial, NotProvided unused, DynamicObject block) {
return injectHelper(frame, ArrayReflector.reflect((Object[]) getStore(array)), array, initial, block, 0);
@Specialization(guards = { "strategy.matches(array)", "!isEmptyArray(array)" }, limit = "ARRAY_STRATEGIES")
public Object injectNoInitial(VirtualFrame frame, DynamicObject array, NotProvided initial, NotProvided unused, DynamicObject block,
@Cached("of(array)") ArrayStrategy strategy) {
final ArrayMirror store = strategy.newMirror(array);
return injectBlockHelper(frame, array, block, store, store.get(0), 1);
}

@Specialization(guards = { "isObjectArray(array)", "!isEmptyArray(array)" })
public Object injectObjectNoInitial(VirtualFrame frame, DynamicObject array, NotProvided initial, NotProvided unused, DynamicObject block) {
final ArrayMirror mirror = ArrayReflector.reflect((Object[]) getStore(array));

return injectHelper(frame, mirror, array, mirror.get(0), block, 1);
}
public Object injectBlockHelper(VirtualFrame frame, DynamicObject array, DynamicObject block, ArrayMirror store, Object initial, int start) {
Object accumulator = initial;
int n = start;
try {
for (; n < getSize(array); n++) {
accumulator = yield(frame, block, accumulator, store.get(n));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
getRootNode().reportLoopCount(n);
}
}

@Specialization(guards = { "isNullArray(array)", "wasProvided(initial)" })
public Object injectNull(VirtualFrame frame, DynamicObject array, Object initial, NotProvided unused, DynamicObject block) {
return initial;
return accumulator;
}

@Specialization(guards = "isNullArray(array)")
public Object injectNullNoInitial(VirtualFrame frame, DynamicObject array, NotProvided initial, NotProvided unused, DynamicObject block) {
return nil();
}
// With Symbol

@Specialization(guards = { "isRubySymbol(symbol)", "isEmptyArray(array)", "wasProvided(initial)" })
public Object injectSymbolEmptyArray(VirtualFrame frame, DynamicObject array, Object initial, DynamicObject symbol, NotProvided block) {
return initial;
}

@Specialization(guards = { "isRubySymbol(symbol)", "isEmptyArray(array)" })
public Object injectSymbolEmptyArray(VirtualFrame frame, DynamicObject array, DynamicObject symbol, NotProvided unused, NotProvided block) {
public Object injectSymbolEmptyArrayNoInitial(VirtualFrame frame, DynamicObject array, DynamicObject symbol, NotProvided unused, NotProvided block) {
return nil();
}

@Specialization(guards = { "isRubySymbol(symbol)", "isIntArray(array)", "!isEmptyArray(array)", "wasProvided(initial)" })
public Object injectSymbolIntArray(VirtualFrame frame, DynamicObject array, Object initial, DynamicObject symbol, NotProvided block) {
return injectSymbolHelper(frame, ArrayReflector.reflect((int[]) getStore(array)), array, initial, symbol, 0);
}

@Specialization(guards = { "isRubySymbol(symbol)", "isIntArray(array)", "!isEmptyArray(array)" })
public Object injectSymbolIntArray(VirtualFrame frame, DynamicObject array, DynamicObject symbol, NotProvided unused, NotProvided block) {
final ArrayMirror mirror = ArrayReflector.reflect((int[]) getStore(array));

return injectSymbolHelper(frame, mirror, array, mirror.get(0), symbol, 1);
}

@Specialization(guards = { "isRubySymbol(symbol)", "isLongArray(array)", "!isEmptyArray(array)", "wasProvided(initial)" })
public Object injectSymbolLongArray(VirtualFrame frame, DynamicObject array, Object initial, DynamicObject symbol, NotProvided block) {
return injectSymbolHelper(frame, ArrayReflector.reflect((long[]) getStore(array)), array, initial, symbol, 0);
}

@Specialization(guards = { "isRubySymbol(symbol)", "isLongArray(array)", "!isEmptyArray(array)" })
public Object injectSymbolLongArray(VirtualFrame frame, DynamicObject array, DynamicObject symbol, NotProvided unused, NotProvided block) {
final ArrayMirror mirror = ArrayReflector.reflect((long[]) getStore(array));

return injectSymbolHelper(frame, mirror, array, mirror.get(0), symbol, 1);
}

@Specialization(guards = { "isRubySymbol(symbol)", "isDoubleArray(array)", "!isEmptyArray(array)", "wasProvided(initial)" })
public Object injectSymbolDoubleArray(VirtualFrame frame, DynamicObject array, Object initial, DynamicObject symbol, NotProvided block) {
return injectSymbolHelper(frame, ArrayReflector.reflect((double[]) getStore(array)), array, initial, symbol, 0);
}

@Specialization(guards = { "isRubySymbol(symbol)", "isDoubleArray(array)", "!isEmptyArray(array)" })
public Object injectSymbolDoubleArray(VirtualFrame frame, DynamicObject array, DynamicObject symbol, NotProvided unused, NotProvided block) {
final ArrayMirror mirror = ArrayReflector.reflect((double[]) getStore(array));

return injectSymbolHelper(frame, mirror, array, mirror.get(0), symbol, 1);
}

@Specialization(guards = { "isRubySymbol(symbol)", "isObjectArray(array)", "!isEmptyArray(array)", "wasProvided(initial)" })
public Object injectSymbolObjectArray(VirtualFrame frame, DynamicObject array, Object initial, DynamicObject symbol, NotProvided block) {
return injectSymbolHelper(frame, ArrayReflector.reflect((Object[]) getStore(array)), array, initial, symbol, 0);
}

@Specialization(guards = { "isRubySymbol(symbol)", "isObjectArray(array)", "!isEmptyArray(array)" })
public Object injectSymbolObjectArray(VirtualFrame frame, DynamicObject array, DynamicObject symbol, NotProvided unused, NotProvided block) {
final ArrayMirror mirror = ArrayReflector.reflect((Object[]) getStore(array));

return injectSymbolHelper(frame, mirror, array, mirror.get(0), symbol, 1);
@Specialization(guards = { "isRubySymbol(symbol)", "strategy.matches(array)", "!isEmptyArray(array)", "wasProvided(initial)" }, limit = "ARRAY_STRATEGIES")
public Object injectSymbolWithInitial(VirtualFrame frame, DynamicObject array, Object initial, DynamicObject symbol, NotProvided block,
@Cached("of(array)") ArrayStrategy strategy) {
final ArrayMirror store = strategy.newMirror(array);
return injectSymbolHelper(frame, array, symbol, store, initial, 0);
}

private Object injectHelper(VirtualFrame frame, ArrayMirror mirror, DynamicObject array, Object initial, DynamicObject block, int startIndex) {
int count = 0;

Object accumulator = initial;

try {
for (int n = startIndex; n < getSize(array); n++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

accumulator = yield(frame, block, accumulator, mirror.get(n));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
getRootNode().reportLoopCount(count);
}
}

return accumulator;
@Specialization(guards = { "isRubySymbol(symbol)", "strategy.matches(array)", "!isEmptyArray(array)" }, limit = "ARRAY_STRATEGIES")
public Object injectSymbolNoInitial(VirtualFrame frame, DynamicObject array, DynamicObject symbol, NotProvided unused, NotProvided block,
@Cached("of(array)") ArrayStrategy strategy) {
final ArrayMirror store = strategy.newMirror(array);
return injectSymbolHelper(frame, array, symbol, store, store.get(0), 1);
}


private Object injectSymbolHelper(VirtualFrame frame, ArrayMirror mirror, DynamicObject array, Object initial, DynamicObject symbol, int startIndex) {
int count = 0;

public Object injectSymbolHelper(VirtualFrame frame, DynamicObject array, DynamicObject symbol, ArrayMirror store, Object initial, int start) {
Object accumulator = initial;
int n = start;

try {
for (int n = startIndex; n < getSize(array); n++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

accumulator = dispatch.call(frame, accumulator, symbol, null, mirror.get(n));
for (; n < getSize(array); n++) {
accumulator = dispatch.call(frame, accumulator, symbol, null, store.get(n));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
getRootNode().reportLoopCount(count);
getRootNode().reportLoopCount(n);
}
}

return accumulator;
}