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

Commits on Jan 22, 2015

  1. Copy the full SHA
    102fd7b View commit details
  2. Copy the full SHA
    c46ad3e View commit details
  3. Copy the full SHA
    e3755c5 View commit details
  4. Copy the full SHA
    5d71187 View commit details
27 changes: 27 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@
import org.jruby.truffle.runtime.methods.MethodLike;
import org.jruby.truffle.runtime.methods.SharedMethodInfo;
import org.jruby.truffle.runtime.util.ArrayUtils;
import org.jruby.util.ByteList;
import org.jruby.util.Memo;

import java.util.ArrayList;
@@ -2716,6 +2717,24 @@ public PackNode(PackNode prev) {
super(prev);
}

@Specialization(guards = {"arrayIsLongs", "formatIsLStar"})
public RubyString packLStar(RubyArray array, RubyString format) {
final int size = array.getSize();
final long[] store = (long[]) array.getStore();
final byte[] bytes = new byte[size * 4];

for (int n = 0; n < size; n++) {
final int value = (int) store[n]; // happy to truncate
final int byteOffset = n * 4;
bytes[byteOffset + 3] = (byte) (value >>> 24);
bytes[byteOffset + 2] = (byte) (value >>> 16);
bytes[byteOffset + 1] = (byte) (value >>> 8);
bytes[byteOffset + 0] = (byte) value;
}

return new RubyString(getContext().getCoreLibrary().getStringClass(), new ByteList(bytes));
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyString pack(RubyArray array, RubyString format) {
@@ -2727,7 +2746,15 @@ public RubyString pack(RubyArray array, RubyString format) {
getContext().getRuntime(),
getContext().toJRuby(array),
getContext().toJRuby(format).getByteList()).getByteList());
}

protected boolean arrayIsLongs(RubyArray array) {
return array.getStore() instanceof long[];
}

protected boolean formatIsLStar(RubyArray array, RubyString format) {
final byte[] bytes = format.getBytes().unsafeBytes();
return format.getBytes().getEncoding().isAsciiCompatible() && format.length() == 2 && bytes[0] == 'L' && bytes[1] == '*';
}

}
Original file line number Diff line number Diff line change
@@ -1603,6 +1603,16 @@ public int randNonZero(int max) {
return getContext().getRandom().nextInt(max);
}

@Specialization(guards = "isZero")
public double randZero(long max) {
return getContext().getRandom().nextDouble();
}

@Specialization(guards = "isNonZero")
public long randNonZero(long max) {
return getContext().getRandom().nextLong() % max;
}

protected boolean isZero(int max) {
return max == 0;
}
@@ -1611,6 +1621,14 @@ protected boolean isNonZero(int max) {
return max != 0;
}

protected boolean isZero(long max) {
return max == 0;
}

protected boolean isNonZero(long max) {
return max != 0;
}

}

@CoreMethod(names = "require", isModuleFunction = true, required = 1)
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;

@@ -106,6 +107,30 @@ public RubyString javaClassOf(Object value) {

}

@CoreMethod(names = "storage_class", onSingleton = true, required = 1)
public abstract static class StorageClassNode extends CoreMethodNode {

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

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

@Specialization
public RubyString javaClassOf(RubyArray array) {
notDesignedForCompilation();

if (array.getStore() == null) {
return getContext().makeString("null");
} else {
return getContext().makeString(array.getStore().getClass().getName());
}
}

}

@CoreMethod(names = "panic", onSingleton = true)
public abstract static class PanicNode extends CoreMethodNode {