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: 7f5056ec91e6
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1aa6c6ca8c87
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on Apr 1, 2016

  1. Copy the full SHA
    2745645 View commit details
  2. Copy the full SHA
    ab42577 View commit details
  3. Copy the full SHA
    1aa6c6c View commit details
Showing with 69 additions and 63 deletions.
  1. +69 −63 truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
132 changes: 69 additions & 63 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@
import org.jruby.truffle.core.CoreSourceSection;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.YieldingCoreMethodNode;
import org.jruby.truffle.core.array.ArrayNodesFactory.ReplaceNodeFactory;
import org.jruby.truffle.core.coerce.ToAryNode;
import org.jruby.truffle.core.coerce.ToAryNodeGen;
import org.jruby.truffle.core.coerce.ToIntNode;
import org.jruby.truffle.core.coerce.ToIntNodeGen;
@@ -88,9 +90,7 @@
import org.jruby.truffle.language.objects.TaintNodeGen;
import org.jruby.truffle.language.yield.YieldNode;
import org.jruby.util.Memo;

import java.util.Arrays;

import static org.jruby.truffle.core.array.ArrayHelpers.createArray;
import static org.jruby.truffle.core.array.ArrayHelpers.getSize;
import static org.jruby.truffle.core.array.ArrayHelpers.getStore;
@@ -1404,44 +1404,6 @@ public abstract static class InitializeNode extends YieldingCoreMethodNode {
public InitializeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

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

DynamicObject copy = null;
if (respondToToAryNode == null) {
CompilerDirectives.transferToInterpreter();
respondToToAryNode = insert(KernelNodesFactory.RespondToNodeFactory.create(getContext(), getSourceSection(), null, null, null));
}
if (respondToToAryNode.doesRespondToString(frame, object, create7BitString("to_ary", UTF8Encoding.INSTANCE), true)) {
if (toAryNode == null) {
CompilerDirectives.transferToInterpreter();
toAryNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext(), true));
}
Object toAryResult = toAryNode.call(frame, object, "to_ary", null);
if (RubyGuards.isRubyArray(toAryResult)) {
copy = (DynamicObject) toAryResult;
}

}

if (copy != null) {
return initialize(array, copy, NotProvided.INSTANCE, NotProvided.INSTANCE);
} else {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
}
int size = toIntNode.doInt(frame, object);
if (size < 0) {
return initializeNegative(array, size, NotProvided.INSTANCE, NotProvided.INSTANCE);
} else {
return initialize(array, size, NotProvided.INSTANCE, NotProvided.INSTANCE);
}

}

}

@Specialization
public DynamicObject initialize(DynamicObject array, NotProvided size, NotProvided defaultValue, NotProvided block) {
@@ -1454,7 +1416,7 @@ public DynamicObject initialize(DynamicObject array, NotProvided size, NotProvid
}

@Specialization(guards = "size >= 0")
public DynamicObject initialize(DynamicObject array, int size, NotProvided defaultValue, NotProvided block) {
public DynamicObject initializeWithSize(DynamicObject array, int size, NotProvided defaultValue, NotProvided block) {
return initialize(array, size, nil(), block);
}

@@ -1542,11 +1504,7 @@ public DynamicObject initializeNegative(DynamicObject array, int size, Object de

@Specialization(guards = { "wasProvided(sizeObject)", "!isInteger(sizeObject)", "wasProvided(defaultValue)" })
public DynamicObject initialize(VirtualFrame frame, DynamicObject array, Object sizeObject, Object defaultValue, NotProvided block) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
}
int size = toIntNode.doInt(frame, sizeObject);
int size = toInt(frame, sizeObject);
if (size < 0) {
return initializeNegative(array, size, defaultValue, NotProvided.INSTANCE);
} else {
@@ -1600,12 +1558,64 @@ public Object initializeNegative(VirtualFrame frame, DynamicObject array, int si
}

@Specialization(guards = "isRubyArray(copy)")
public DynamicObject initialize(DynamicObject array, DynamicObject copy, NotProvided defaultValue, Object maybeBlock) {
CompilerDirectives.transferToInterpreter();
setStoreAndSize(array, ArrayOperations.toObjectArray(copy), getSize(copy));
public DynamicObject initializeFromArray(DynamicObject array, DynamicObject copy, NotProvided defaultValue, Object maybeBlock,
@Cached("createReplaceNode()") ReplaceNode replaceNode) {
replaceNode.executeReplace(array, copy);
return array;
}

@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) {

DynamicObject copy = null;
if (respondToToAry(frame, object)) {
Object toAryResult = callToAry(frame, object);
if (RubyGuards.isRubyArray(toAryResult)) {
copy = (DynamicObject) toAryResult;
}
}

if (copy != null) {
return initializeFromArray(array, copy, NotProvided.INSTANCE, NotProvided.INSTANCE, replaceNode);
} else {
int size = toInt(frame, object);
if (size < 0) {
return initializeNegative(array, size, NotProvided.INSTANCE, NotProvided.INSTANCE);
} else {
return initializeWithSize(array, size, NotProvided.INSTANCE, NotProvided.INSTANCE);
}
}
}

public boolean respondToToAry(VirtualFrame frame, Object object) {
if (respondToToAryNode == null) {
CompilerDirectives.transferToInterpreter();
respondToToAryNode = insert(KernelNodesFactory.RespondToNodeFactory.create(getContext(), getSourceSection(), null, null, null));
}
return respondToToAryNode.doesRespondToString(frame, object, create7BitString("to_ary", UTF8Encoding.INSTANCE), true);
}

protected Object callToAry(VirtualFrame frame, Object object) {
if (toAryNode == null) {
CompilerDirectives.transferToInterpreter();
toAryNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext(), true));
}
return toAryNode.call(frame, object, "to_ary", null);
}

protected int toInt(VirtualFrame frame, Object value) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeGen.create(getContext(), getSourceSection(), null));
}
return toIntNode.doInt(frame, value);
}

protected ReplaceNode createReplaceNode() {
return ReplaceNodeFactory.create(getContext(), getSourceSection(), null, null);
}

}

@CoreMethod(names = "initialize_copy", required = 1, raiseIfFrozenSelf = true)
@@ -3459,47 +3469,43 @@ public ReplaceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public abstract DynamicObject executeReplace(DynamicObject array, DynamicObject other);

@CreateCast("other") public RubyNode coerceOtherToAry(RubyNode index) {
return ToAryNodeGen.create(getContext(), getSourceSection(), index);
}

@Specialization(guards = {"isRubyArray(other)", "isNullArray(other)"})
public DynamicObject replace(DynamicObject array, DynamicObject other) {
CompilerDirectives.transferToInterpreter();

setStoreAndSize(array, null, 0);
return array;
}

@Specialization(guards = {"isRubyArray(other)", "isIntArray(other)"})
public DynamicObject replaceIntegerFixnum(DynamicObject array, DynamicObject other) {
CompilerDirectives.transferToInterpreter();

setStoreAndSize(array, Arrays.copyOf((int[]) getStore(other), getSize(other)), getSize(other));
final int[] store = (int[]) getStore(other);
setStoreAndSize(array, store.clone(), getSize(other));
return array;
}

@Specialization(guards = {"isRubyArray(other)", "isLongArray(other)"})
public DynamicObject replaceLongFixnum(DynamicObject array, DynamicObject other) {
CompilerDirectives.transferToInterpreter();

setStoreAndSize(array, Arrays.copyOf((long[]) getStore(other), getSize(other)), getSize(other));
final long[] store = (long[]) getStore(other);
setStoreAndSize(array, store.clone(), getSize(other));
return array;
}

@Specialization(guards = {"isRubyArray(other)", "isDoubleArray(other)"})
public DynamicObject replaceFloat(DynamicObject array, DynamicObject other) {
CompilerDirectives.transferToInterpreter();

setStoreAndSize(array, Arrays.copyOf((double[]) getStore(other), getSize(other)), getSize(other));
final double[] store = (double[]) getStore(other);
setStoreAndSize(array, store.clone(), getSize(other));
return array;
}

@Specialization(guards = {"isRubyArray(other)", "isObjectArray(other)"})
public DynamicObject replaceObject(DynamicObject array, DynamicObject other) {
CompilerDirectives.transferToInterpreter();

setStoreAndSize(array, Arrays.copyOf((Object[]) getStore(other), getSize(other)), getSize(other));
final Object[] store = (Object[]) getStore(other);
setStoreAndSize(array, store.clone(), getSize(other));
return array;
}