Skip to content

Commit

Permalink
[Truffle] Completed String#replace.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 23, 2015
1 parent b79e7f2 commit 48072b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/string/replace_tags.txt

This file was deleted.

Expand Up @@ -1595,7 +1595,11 @@ public int ord(RubyString string) {
}

@CoreMethod(names = "replace", required = 1, raiseIfFrozenSelf = true, taintFromParameters = 0)
public abstract static class ReplaceNode extends CoreMethodNode {
@NodeChildren({
@NodeChild(value = "string"),
@NodeChild(value = "other")
})
public abstract static class ReplaceNode extends RubyNode {

public ReplaceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand All @@ -1605,15 +1609,18 @@ public ReplaceNode(ReplaceNode prev) {
super(prev);
}

@CreateCast("other") public RubyNode coerceOtherToString(RubyNode other) {
return ToStrNodeFactory.create(getContext(), getSourceSection(), other);
}

@Specialization
public RubyString replace(RubyString string, RubyString other) {
notDesignedForCompilation();

if (string == other) {
return string;
}

string.getByteList().replace(other.getByteList().bytes());
string.getByteList().setEncoding(other.getByteList().getEncoding());
string.setCodeRange(other.getCodeRange());

return string;
Expand Down

0 comments on commit 48072b4

Please sign in to comment.