Skip to content

Commit

Permalink
Backport two more names from versioned method removal
Browse files Browse the repository at this point in the history
See ruby/stringio#84 and ruby/stringio#88 for info on this
transition.
  • Loading branch information
headius committed Mar 13, 2024
1 parent 2476e8b commit 4fdce77
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ public IRubyObject primitive_convert(ThreadContext context, IRubyObject[] args)
inBytes = new ByteList();
} else {
input = args[0].convertToString();
input.modify19();
input.modifyAndClearCodeRange();
inBytes = input.getByteList();
}

output = args[1].convertToString();
output.modify19();
output.modifyAndClearCodeRange();
outBytes = output.getByteList();

Ptr inPtr = new Ptr();
Expand Down
45 changes: 29 additions & 16 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,12 @@ public final void modify() {
value.invalidate();
}

@Deprecated
public final void modify19() {
modifyAndClearCodeRange();
}

public final void modifyAndClearCodeRange() {
modify();
clearCodeRange();
}
Expand Down Expand Up @@ -2636,7 +2641,7 @@ public char charAt(int offset) {

@Override
public CharSequence subSequence(int start, int end) {
IRubyObject subStr = substr19(getRuntime(), start, end - start);
IRubyObject subStr = substrEnc(getRuntime(), start, end - start);
if (subStr.isNil()) {
throw new StringIndexOutOfBoundsException("String index out of range: <" + start + ", " + end + ")");
}
Expand Down Expand Up @@ -3132,7 +3137,7 @@ private RubyString subBangCommon(ThreadContext context, final int beg, final int
if (replSize > plen) {
modifyExpand(value.getRealSize() + replSize - plen);
} else {
modify19();
modifyAndClearCodeRange();
}

final ByteList value = this.value;
Expand Down Expand Up @@ -3689,7 +3694,12 @@ private IRubyObject byteARef(Ruby runtime, IRubyObject idx) {
return obj;
}

@Deprecated
public final IRubyObject substr19(Ruby runtime, int beg, int len) {
return substrEnc(runtime, beg, len);
}

public final IRubyObject substrEnc(Ruby runtime, int beg, int len) {
if (len < 0) return runtime.getNil();
int length = value.getRealSize();
if (length == 0) len = 0;
Expand Down Expand Up @@ -3816,15 +3826,15 @@ public IRubyObject op_aref(ThreadContext context, IRubyObject arg) {
} else if (arg instanceof RubyRange) {
int len = strLength();
int[] begLen = ((RubyRange) arg).begLenInt(len, 0);
return begLen == null ? context.nil : substr19(runtime, begLen[0], begLen[1]);
return begLen == null ? context.nil : substrEnc(runtime, begLen[0], begLen[1]);
} else {
StringSites sites = sites(context);
if (RubyRange.isRangeLike(context, arg, sites.respond_to_begin, sites.respond_to_end)) {
int len = strLength();
RubyRange range = RubyRange.rangeFromRangeLike(context, arg, sites.begin, sites.end, sites.exclude_end);

int[] begLen = range.begLenInt(len, 0);
return begLen == null ? context.nil : substr19(runtime, begLen[0], begLen[1]);
return begLen == null ? context.nil : substrEnc(runtime, begLen[0], begLen[1]);
}
}
return op_aref(runtime, RubyNumeric.num2int(arg));
Expand All @@ -3834,7 +3844,8 @@ public IRubyObject op_aref(ThreadContext context, IRubyObject arg) {
public IRubyObject op_aref(ThreadContext context, IRubyObject arg1, IRubyObject arg2) {
Ruby runtime = context.runtime;
if (arg1 instanceof RubyRegexp) return subpat(context, (RubyRegexp) arg1, arg2);
return substr19(runtime, RubyNumeric.num2int(arg1), RubyNumeric.num2int(arg2));
int beg = RubyNumeric.num2int(arg1);
return substrEnc(runtime, beg, RubyNumeric.num2int(arg2));
}

@JRubyMethod
Expand All @@ -3848,7 +3859,7 @@ public IRubyObject byteslice(ThreadContext context, IRubyObject arg) {
}

private IRubyObject op_aref(Ruby runtime, int idx) {
IRubyObject str = substr19(runtime, idx, 1);
IRubyObject str = substrEnc(runtime, idx, 1);
return !str.isNil() && ((RubyString) str).value.getRealSize() == 0 ? runtime.getNil() : str;
}

Expand Down Expand Up @@ -4244,7 +4255,7 @@ public RubyBoolean include_p(ThreadContext context, IRubyObject obj) {

@JRubyMethod
public IRubyObject chr(ThreadContext context) {
return substr19(context.runtime, 0, 1);
return substrEnc(context.runtime, 0, 1);
}

@JRubyMethod
Expand All @@ -4264,7 +4275,7 @@ public IRubyObject setbyte(ThreadContext context, IRubyObject index, IRubyObject
IRubyObject w = v.modulo(context, (long)256);
int b = RubyNumeric.num2int(w) & 0xff;

modify19();
modifyAndClearCodeRange();
value.getUnsafeBytes()[normalizedIndex] = (byte)b;
return val;
}
Expand Down Expand Up @@ -5386,10 +5397,12 @@ public IRubyObject rpartition(ThreadContext context, IRubyObject arg) {
if (pos < 0) return rpartitionMismatch(runtime);
}

int beg = pos + sep.strLength();
int len = value.getRealSize();
return RubyArray.newArrayNoCopy(runtime, new IRubyObject[] {
substr19(runtime, 0, pos),
substrEnc(runtime, 0, pos),
sep,
substr19(runtime, pos + sep.strLength(), value.getRealSize())
substrEnc(runtime, beg, len)
});
}

Expand Down Expand Up @@ -6616,28 +6629,28 @@ public IRubyObject encoding(ThreadContext context) {

@JRubyMethod(name = "encode!")
public IRubyObject encode_bang(ThreadContext context) {
modify19();
modifyAndClearCodeRange();

return EncodingUtils.strTranscode(context, this, RubyString::updateFromTranscode);
}

@JRubyMethod(name = "encode!")
public IRubyObject encode_bang(ThreadContext context, IRubyObject arg0) {
modify19();
modifyAndClearCodeRange();

return EncodingUtils.strTranscode(context, arg0, this, RubyString::updateFromTranscode);
}

@JRubyMethod(name = "encode!")
public IRubyObject encode_bang(ThreadContext context, IRubyObject arg0, IRubyObject arg1) {
modify19();
modifyAndClearCodeRange();

return EncodingUtils.strTranscode(context, arg0, arg1, this, RubyString::updateFromTranscode);
}

@JRubyMethod(name = "encode!")
public IRubyObject encode_bang(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
modify19();
modifyAndClearCodeRange();

return EncodingUtils.strTranscode(context, arg0, arg1, arg2, this, RubyString::updateFromTranscode);
}
Expand Down Expand Up @@ -6682,7 +6695,7 @@ public IRubyObject force_encoding(ThreadContext context, IRubyObject enc) {

private IRubyObject force_encoding(Encoding encoding) {
modifyCheck();
modify19();
modifyAndClearCodeRange();
associateEncoding(encoding);
clearCodeRange();
return this;
Expand Down Expand Up @@ -7270,7 +7283,7 @@ public RubyArray unpack(IRubyObject obj) {
public IRubyObject encode_bang(ThreadContext context, IRubyObject[] args) {
Arity.checkArgumentCount(context, args, 0, 2);

modify19();
modifyAndClearCodeRange();

return EncodingUtils.strTranscode(context, args, this, RubyString::updateFromTranscode);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ext/date/RubyDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@ private static IRubyObject s3e(ThreadContext context, final RubyHash hash,
int ep = skipDigits(y, s);
if (ep != y.strLength()) {
oy = y; y = d;
d = (RubyString) oy.substr19(context.runtime, bp, ep - bp);
d = (RubyString) oy.substrEnc(context.runtime, bp, ep - bp);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ext/ripper/RubyRipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public IRubyObject yydebug_set(ThreadContext context, IRubyObject arg) {
public static IRubyObject dedent_string(ThreadContext context, IRubyObject self, IRubyObject _input, IRubyObject _width) {
RubyString input = _input.convertToString();
int wid = _width.convertToInteger().getIntValue();
input.modify19();
input.modifyAndClearCodeRange();
int col = LexingCommon.dedent_string(input.getByteList(), wid);
return context.runtime.newFixnum(col);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/io/EncodingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ public static RubyString encodedDup(ThreadContext context, RubyString str, Encod
// set to same superclass
newstr.setMetaClass(str.getMetaClass());
}
newstr.modify19();
newstr.modifyAndClearCodeRange();
return strEncodeAssociate(newstr, encindex);
}

Expand Down

0 comments on commit 4fdce77

Please sign in to comment.