Skip to content

Commit

Permalink
Backport cat19 name change to support StringIO migration
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 12, 2024
1 parent 2caaa50 commit 4114fc5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -1404,22 +1404,37 @@ public final RubyString cat(byte[] str, int beg, int len) {
return this;
}

// // rb_str_buf_append against VALUE
// Needs to remain in place until StringIO has migrated to the new methods
// See https://github.com/ruby/stringio/issues/83
@Deprecated
public final RubyString cat19(RubyString str2) {
int str2_cr = cat19(str2.getByteList(), str2.getCodeRange());
return catWithCodeRange(str2);
}

// // rb_str_buf_append against VALUE
public final RubyString catWithCodeRange(RubyString str2) {
ByteList other = str2.getByteList();
int str2_cr = catWithCodeRange(other, str2.getCodeRange());

str2.setCodeRange(str2_cr);

return this;
}

public final RubyString cat(ByteList other, int codeRange) {
cat19(other, codeRange);
catWithCodeRange(other, codeRange);
return this;
}

// rb_str_buf_append against ptr
// Needs to remain in place until StringIO has migrated to the new methods
// See https://github.com/ruby/stringio/issues/83
@Deprecated
public final int cat19(ByteList other, int codeRange) {
return catWithCodeRange(other, codeRange);
}

// rb_str_buf_append against ptr
public final int catWithCodeRange(ByteList other, int codeRange) {
return EncodingUtils.encCrStrBufCat(metaClass.runtime, this, other, other.getEncoding(), codeRange);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ public void BuildCompoundStringInstr(BuildCompoundStringInstr compoundstring) {
// we have bytelist and CR in hand, go straight to cat logic
FrozenString str = (FrozenString) p;
jvmMethod().getValueCompiler().pushFrozenString(str.getByteList(), str.getCodeRange(), str.getFile(), str.getLine());
jvmAdapter().invokevirtual(p(RubyString.class), "cat19", sig(RubyString.class, RubyString.class));
jvmAdapter().invokevirtual(p(RubyString.class), "catWithCodeRange", sig(RubyString.class, RubyString.class));
} else if (p instanceof StringLiteral) {
StringLiteral str = (StringLiteral) p;
jvmMethod().getValueCompiler().pushByteList(str.getByteList());
Expand Down

0 comments on commit 4114fc5

Please sign in to comment.