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

Commits on Feb 6, 2015

  1. [Truffle] Array#clear is fine for compilation, and we shouldn't throw…

    … away any existing storage or specialization.
    chrisseaton committed Feb 6, 2015
    Copy the full SHA
    f5d97c9 View commit details
  2. Copy the full SHA
    e8e3278 View commit details
  3. Copy the full SHA
    74e693c View commit details
123 changes: 1 addition & 122 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -897,8 +897,7 @@ public ClearNode(ClearNode prev) {

@Specialization
public RubyArray clear(RubyArray array) {
notDesignedForCompilation();
array.setStore(null, 0);
array.setStore(array.getStore(), 0);
return array;
}

@@ -1386,126 +1385,6 @@ public Object eachWithIndexObject(VirtualFrame frame, RubyArray array, RubyProc

}

@CoreMethod(names = "empty?")
public abstract static class EmptyNode extends ArrayCoreMethodNode {

public EmptyNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public EmptyNode(EmptyNode prev) {
super(prev);
}

@Specialization
public boolean isEmpty(RubyArray array) {
return array.getSize() == 0;
}

}

@CoreMethod(names = "find", needsBlock = true)
@ImportGuards(ArrayGuards.class)
public abstract static class FindNode extends YieldingCoreMethodNode {

public FindNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public FindNode(FindNode prev) {
super(prev);
}

@Specialization(guards = "isNull")
public Object findNull(VirtualFrame frame, RubyArray array, RubyProc block) {
return getContext().getCoreLibrary().getNilObject();
}

@Specialization(guards = "isIntegerFixnum")
public Object findIntegerFixnum(VirtualFrame frame, RubyArray array, RubyProc block) {
notDesignedForCompilation();

final int[] store = (int[]) array.getStore();

for (int n = 0; n < array.getSize(); n++) {
try {
final Object value = store[n];

if (yieldIsTruthy(frame, block, value)) {
return value;
}
} catch (BreakException e) {
break;
}
}

return getContext().getCoreLibrary().getNilObject();
}

@Specialization(guards = "isLongFixnum")
public Object findLongFixnum(VirtualFrame frame, RubyArray array, RubyProc block) {
notDesignedForCompilation();

final long[] store = (long[]) array.getStore();

for (int n = 0; n < array.getSize(); n++) {
try {
final Object value = store[n];

if (yieldIsTruthy(frame, block, value)) {
return value;
}
} catch (BreakException e) {
break;
}
}

return getContext().getCoreLibrary().getNilObject();
}

@Specialization(guards = "isFloat")
public Object findFloat(VirtualFrame frame, RubyArray array, RubyProc block) {
notDesignedForCompilation();

final double[] store = (double[]) array.getStore();

for (int n = 0; n < array.getSize(); n++) {
try {
final Object value = store[n];

if (yieldIsTruthy(frame, block, value)) {
return value;
}
} catch (BreakException e) {
break;
}
}

return getContext().getCoreLibrary().getNilObject();
}

@Specialization(guards = "isObject")
public Object findObject(VirtualFrame frame, RubyArray array, RubyProc block) {
notDesignedForCompilation();

final Object[] store = (Object[]) array.getStore();

for (int n = 0; n < array.getSize(); n++) {
try {
final Object value = store[n];

if (yieldIsTruthy(frame, block, value)) {
return value;
}
} catch (BreakException e) {
break;
}
}

return getContext().getCoreLibrary().getNilObject();
}
}

@CoreMethod(names = "flatten")
public abstract static class FlattenNode extends ArrayCoreMethodNode {

Original file line number Diff line number Diff line change
@@ -305,4 +305,8 @@ def eql?(other)
true
end

def empty?
@total == 0
end

end