Skip to content

Commit 48072b4

Browse files
committed
[Truffle] Completed String#replace.
1 parent b79e7f2 commit 48072b4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

spec/truffle/tags/core/string/replace_tags.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,11 @@ public int ord(RubyString string) {
15951595
}
15961596

15971597
@CoreMethod(names = "replace", required = 1, raiseIfFrozenSelf = true, taintFromParameters = 0)
1598-
public abstract static class ReplaceNode extends CoreMethodNode {
1598+
@NodeChildren({
1599+
@NodeChild(value = "string"),
1600+
@NodeChild(value = "other")
1601+
})
1602+
public abstract static class ReplaceNode extends RubyNode {
15991603

16001604
public ReplaceNode(RubyContext context, SourceSection sourceSection) {
16011605
super(context, sourceSection);
@@ -1605,15 +1609,18 @@ public ReplaceNode(ReplaceNode prev) {
16051609
super(prev);
16061610
}
16071611

1612+
@CreateCast("other") public RubyNode coerceOtherToString(RubyNode other) {
1613+
return ToStrNodeFactory.create(getContext(), getSourceSection(), other);
1614+
}
1615+
16081616
@Specialization
16091617
public RubyString replace(RubyString string, RubyString other) {
1610-
notDesignedForCompilation();
1611-
16121618
if (string == other) {
16131619
return string;
16141620
}
16151621

16161622
string.getByteList().replace(other.getByteList().bytes());
1623+
string.getByteList().setEncoding(other.getByteList().getEncoding());
16171624
string.setCodeRange(other.getCodeRange());
16181625

16191626
return string;

0 commit comments

Comments
 (0)