Skip to content

Commit

Permalink
[Truffle] Add Method#hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Fish committed Sep 15, 2016
1 parent a9b6515 commit 93cc335
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/method/hash_tags.txt

This file was deleted.

Expand Up @@ -20,8 +20,10 @@
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import jnr.ffi.annotations.In;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.ArgumentDescriptor;
import org.jruby.runtime.Helpers;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.builtins.CoreClass;
Expand Down Expand Up @@ -104,6 +106,20 @@ public DynamicObject name(DynamicObject method) {

}

@CoreMethod(names = "hash")
public abstract static class HashNode extends CoreMethodArrayArgumentsNode {

@Specialization
public long hash(DynamicObject rubyMethod) {
final InternalMethod method = Layouts.METHOD.getMethod(rubyMethod);
long h = Helpers.hashStart(getContext().getJRubyRuntime(), method.getDeclaringModule().hashCode());
h = Helpers.murmurCombine(h, Layouts.METHOD.getReceiver(rubyMethod).hashCode());
h = Helpers.murmurCombine(h, method.getSharedMethodInfo().hashCode());
return Helpers.hashEnd(h);
}

}

@CoreMethod(names = "owner")
public abstract static class OwnerNode extends CoreMethodArrayArgumentsNode {

Expand Down

0 comments on commit 93cc335

Please sign in to comment.