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

Commits on Nov 5, 2014

  1. Copy the full SHA
    dd2fd1a View commit details
  2. Copy the full SHA
    36541a7 View commit details
Original file line number Diff line number Diff line change
@@ -98,9 +98,9 @@ public Object isDefined(VirtualFrame frame) {
}

LexicalScope lexicalScope = getLexicalScope(frame);
Object value = ModuleOperations.lookupConstant(lexicalScope, (RubyModule) receiverObject, name);
RubyConstant constant = ModuleOperations.lookupConstant(lexicalScope, (RubyModule) receiverObject, name);

if (value == null) {
if (constant == null) {
return getContext().getCoreLibrary().getNilObject();
} else {
return context.makeString("constant");
Original file line number Diff line number Diff line change
@@ -9,12 +9,11 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.dsl.ImportGuards;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyHash;

import java.util.LinkedHashMap;

@ImportGuards(HashGuards.class)
public abstract class HashCoreMethodNode extends CoreMethodNode {

public HashCoreMethodNode(RubyContext context, SourceSection sourceSection) {
@@ -25,28 +24,4 @@ public HashCoreMethodNode(HashCoreMethodNode prev) {
super(prev);
}

protected boolean isNull(RubyHash hash) {
return hash.getStore() == null;
}

protected boolean isObjectArray(RubyHash hash) {
return hash.getStore() instanceof Object[];
}

protected boolean isObjectLinkedHashMap(RubyHash hash) {
return hash.getStore() instanceof LinkedHashMap<?, ?>;
}

protected boolean isOtherNull(RubyHash hash, RubyHash other) {
return other.getStore() == null;
}

protected boolean isOtherObjectArray(RubyHash hash, RubyHash other) {
return other.getStore() instanceof Object[];
}

protected boolean isOtherObjectLinkedHashMap(RubyHash hash, RubyHash other) {
return other.getStore() instanceof LinkedHashMap<?, ?>;
}

}
42 changes: 42 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/HashGuards.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.core;

import org.jruby.truffle.runtime.core.RubyHash;

import java.util.LinkedHashMap;

public class HashGuards {

public static boolean isNull(RubyHash hash) {
return hash.getStore() == null;
}

public static boolean isObjectArray(RubyHash hash) {
return hash.getStore() instanceof Object[];
}

public static boolean isObjectLinkedHashMap(RubyHash hash) {
return hash.getStore() instanceof LinkedHashMap<?, ?>;
}

public static boolean isOtherNull(RubyHash hash, RubyHash other) {
return other.getStore() == null;
}

public static boolean isOtherObjectArray(RubyHash hash, RubyHash other) {
return other.getStore() instanceof Object[];
}

public static boolean isOtherObjectLinkedHashMap(RubyHash hash, RubyHash other) {
return other.getStore() instanceof LinkedHashMap<?, ?>;
}

}
Original file line number Diff line number Diff line change
@@ -474,7 +474,8 @@ public RubyHash dupObjectLinkedHashMap(RubyHash hash) {
}

@CoreMethod(names = "each", needsBlock = true)
public abstract static class EachNode extends YieldingHashCoreMethodNode {
@ImportGuards(HashGuards.class)
public abstract static class EachNode extends YieldingCoreMethodNode {

public EachNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
@@ -727,7 +728,8 @@ public RubyString inspectObjectLinkedHashMap(VirtualFrame frame, RubyHash hash)
}

@CoreMethod(names = {"map", "collect"}, needsBlock = true)
public abstract static class MapNode extends YieldingHashCoreMethodNode {
@ImportGuards(HashGuards.class)
public abstract static class MapNode extends YieldingCoreMethodNode {

public MapNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);