Skip to content


Browse files Browse the repository at this point in the history
[Truffle] Handle String coercion in Encoding.find.
  • Loading branch information
nirvdrum committed Feb 6, 2015
1 parent a005832 commit 0a7f712
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/encoding/find_tags.txt
@@ -1,6 +1,5 @@
fails:Encoding.find returns the corresponding Encoding object if given a valid alias name
fails:Encoding.find returns the passed Encoding object
fails:Encoding.find accepts any object as encoding name, if it responds to #to_str
fails:Encoding.find raises an ArgumentError if the given encoding does not exist
fails:Encoding.find supports the 'locale' encoding alias
fails:Encoding.find returns default external encoding for the 'external' encoding alias
Expand Down
Expand Up @@ -10,6 +10,8 @@
package org.jruby.truffle.nodes.core;

Expand All @@ -20,6 +22,8 @@
import org.jcodings.util.CaseInsensitiveBytesHash;
import org.jcodings.util.Hash;
import org.jruby.runtime.encoding.EncodingService;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.coerce.ToStrNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyEncoding;
Expand Down Expand Up @@ -224,7 +228,8 @@ public RubyNilClass defaultExternal(RubyNilClass encoding) {

@CoreMethod(names = "find", onSingleton = true, required = 1)
public abstract static class FindNode extends CoreMethodNode {
@NodeChild(value = "name")
public abstract static class FindNode extends RubyNode {

public FindNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand All @@ -234,6 +239,10 @@ public FindNode(FindNode prev) {

@CreateCast("name") public RubyNode coerceNameToString(RubyNode name) {
return ToStrNodeFactory.create(getContext(), getSourceSection(), name);

public RubyEncoding find(RubyString name) {
Expand Down

2 comments on commit 0a7f712

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's simpler than a Rubinius fallback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another benefit of this approach is it cuts down on the number of specializations, which cuts down on the amount of generated code.

Please sign in to comment.