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: d38633865309
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 26de15d0585c
Choose a head ref
  • 6 commits
  • 11 files changed
  • 1 contributor

Commits on May 30, 2018

  1. make getClass/getModule behave exactly the same + add Ruby#getModule

    ... since it led to confusion on the native side a few time already
    as `getClass(name)` would return null for cases when the constant is
    there but isn't a class instead of failing early (like `getModule()`)
    kares committed May 30, 2018
    Copy the full SHA
    3305d4b View commit details
  2. Copy the full SHA
    ade8e11 View commit details
  3. Copy the full SHA
    34974ca View commit details
  4. Copy the full SHA
    0028363 View commit details
  5. Copy the full SHA
    4c9431f View commit details
  6. [fix] use string-check set method for Hash[] to freeze up keys

    ... also use the same fastASet... in both Array/Hash argument paths
    we have a couple of Hash overrides but none have the method reachable
    so it is expected to be fine
    kares committed May 30, 2018
    Copy the full SHA
    26de15d View commit details
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -961,7 +961,7 @@ public void eachModule(Function1<Object, IRubyObject> func) {
* @return The module or null if not found
*/
public RubyModule getModule(String name) {
return (RubyModule) objectClass.getConstantAt(name);
return objectClass.getModule(name);
}

@Deprecated
@@ -1008,7 +1008,7 @@ public RubyClass defineClass(String name, RubyClass superClass, ObjectAllocator
}

/**
* A variation of defineClass that allows passing in an array of subplementary
* A variation of defineClass that allows passing in an array of supplementary
* call sites for improving dynamic invocation performance.
*
* @param name The name for the new class
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -527,6 +527,10 @@ public final RubyClass getMetaClass() {
return metaClass;
}

static RubyClass getMetaClass(IRubyObject arg) {
return ((RubyBasicObject) arg).metaClass;
}

/** rb_singleton_class
*
* Note: this method is specialized for RubyFixnum, RubySymbol,
35 changes: 16 additions & 19 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -149,42 +149,39 @@ public ClassIndex getNativeClassIndex() {
*/
@JRubyMethod(name = "[]", rest = true, meta = true)
public static IRubyObject create(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
RubyClass klass = (RubyClass) recv;
Ruby runtime = context.runtime;
RubyHash hash;
final Ruby runtime = context.runtime;

if (args.length == 1) {
IRubyObject tmp = TypeConverter.convertToTypeWithCheck(
args[0], runtime.getHash(), "to_hash");

if (!tmp.isNil()) {
RubyHash otherHash = (RubyHash) tmp;
return new RubyHash(runtime, klass, otherHash);
if (tmp != context.nil) {
return new RubyHash(runtime, (RubyClass) recv, (RubyHash) tmp);
}

tmp = TypeConverter.convertToTypeWithCheck(args[0], runtime.getArray(), "to_ary");
if (!tmp.isNil()) {
hash = (RubyHash)klass.allocate();
RubyArray arr = (RubyArray)tmp;
for(int i = 0, j = arr.getLength(); i<j; i++) {
if (tmp != context.nil) {
RubyHash hash = (RubyHash) ((RubyClass) recv).allocate();
RubyArray arr = (RubyArray) tmp;
for (int i = 0, j = arr.getLength(); i<j; i++) {
IRubyObject e = arr.entry(i);
IRubyObject v = TypeConverter.convertToTypeWithCheck(e, runtime.getArray(), "to_ary");
IRubyObject key;
IRubyObject val = runtime.getNil();
if(v.isNil()) {
if (v == context.nil) {
runtime.getWarnings().warn("wrong element type " + e.getMetaClass() + " at " + i + " (expected array)");
runtime.getWarnings().warn("ignoring wrong elements is deprecated, remove them explicitly");
runtime.getWarnings().warn("this causes ArgumentError in the next release");
continue;
}
switch(((RubyArray)v).getLength()) {
switch (((RubyArray) v).getLength()) {
default:
throw runtime.newArgumentError("invalid number of elements (" + ((RubyArray)v).getLength() + " for 1..2)");
case 2:
val = ((RubyArray)v).entry(1);
throw runtime.newArgumentError("invalid number of elements (" + ((RubyArray) v).getLength() + " for 1..2)");
case 2:
val = ((RubyArray) v).entry(1);
case 1:
key = ((RubyArray)v).entry(0);
hash.fastASet(key, val);
key = ((RubyArray) v).entry(0);
hash.fastASetCheckString(runtime, key, val);
}
}
return hash;
@@ -195,8 +192,8 @@ public static IRubyObject create(ThreadContext context, IRubyObject recv, IRubyO
throw runtime.newArgumentError("odd number of arguments for Hash");
}

hash = (RubyHash)klass.allocate();
for (int i=0; i < args.length; i+=2) hash.op_aset(context, args[i], args[i+1]);
RubyHash hash = (RubyHash) ((RubyClass) recv).allocate();
for (int i=0; i < args.length; i+=2) hash.fastASetCheckString(runtime, args[i], args[i+1]);

return hash;
}
Loading