Skip to content

Commit

Permalink
Migrate all callers of cat19 to new names
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 12, 2024
1 parent 4114fc5 commit 2476e8b
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 70 deletions.
10 changes: 4 additions & 6 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.io.IOException;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
Expand All @@ -59,7 +58,6 @@
import org.jruby.ast.util.ArgsUtil;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.exceptions.RaiseException;
import org.jruby.exceptions.RangeError;
import org.jruby.java.util.ArrayUtils;
import org.jruby.javasupport.JavaUtil;
import org.jruby.runtime.Arity;
Expand Down Expand Up @@ -1851,7 +1849,7 @@ protected IRubyObject inspectAry(ThreadContext context) {
} else {
EncodingUtils.encAssociateIndex(str, s.getEncoding());
}
str.cat19(s);
str.catWithCodeRange(s);
}
str.cat((byte) ']');

Expand Down Expand Up @@ -2088,7 +2086,7 @@ protected int joinStrings(RubyString sep, int max, RubyString result) {
for (i = 0; i < max; i++) {
IRubyObject val = eltInternal(i);
if (!(val instanceof RubyString)) break;
if (i > 0 && sep != null) result.cat19(sep);
if (i > 0 && sep != null) result.catWithCodeRange(sep);
result.append(val);
}
} catch (ArrayIndexOutOfBoundsException e) {
Expand All @@ -2106,7 +2104,7 @@ private RubyString joinAny(ThreadContext context, RubyString sep, int i, RubyStr
JavaSites.CheckedSites to_ary_checked = null;

for (; i < realLength; i++) {
if (i > 0 && sep != null) result.cat19(sep);
if (i > 0 && sep != null) result.catWithCodeRange(sep);

IRubyObject val = eltOk(i);

Expand Down Expand Up @@ -2137,7 +2135,7 @@ private RubyString joinAny(ThreadContext context, RubyString sep, int i, RubyStr

// MRI: ary_join_1, str_join label
private static void strJoin(RubyString result, RubyString val, boolean[] first) {
result.cat19(val);
result.catWithCodeRange(val);
if (first[0]) {
result.setEncoding(val.getEncoding());
first[0] = false;
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyEnumerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ private IRubyObject inspect(ThreadContext context, boolean recurse) {
if (recurse) {
return result.catString("...>");
} else {
result.cat19(RubyObject.inspect(context, object));
result.catWithCodeRange(RubyObject.inspect(context, object));
result.cat(':');
result.cat19(getMethod().asString());
result.catWithCodeRange(getMethod().asString());
if (methodArgs.length > 0) {
result.cat('(');
for (int i= 0; i < methodArgs.length; i++) {
if (methodArgsHasKeywords && i == 0) break;
result.cat19(RubyObject.inspect(context, methodArgs[i]));
result.catWithCodeRange(RubyObject.inspect(context, methodArgs[i]));
if (i < methodArgs.length - 1) {
result.catString(", ");
} else {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -928,9 +928,9 @@ public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyOb

if (index > 0) bytes.append((byte) ',').append((byte) ' ');

str.cat19(keyStr);
str.catWithCodeRange(keyStr);
bytes.append((byte) '=').append((byte) '>');
str.cat19(valStr);
str.catWithCodeRange(valStr);
}
};

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,8 @@ public static IRubyObject trace_var(ThreadContext context, IRubyObject recv, IRu
proc = RubyProc.newProc(context.runtime, block, Block.Type.PROC);
} else if (argc == 2) {
if (args[1] instanceof RubyString) {
RubyString s = context.runtime.newString("proc {").cat19(((RubyString) args[1])).cat('}');
RubyString rubyString = context.runtime.newString("proc {");
RubyString s = rubyString.catWithCodeRange(((RubyString) args[1])).cat('}');
proc = (RubyProc) evalCommon(context, recv, new IRubyObject[] { s });
} else {
proc = (RubyProc) TypeConverter.convertToType(args[1], context.runtime.getProc(), "to_proc", true);
Expand Down
10 changes: 4 additions & 6 deletions core/src/main/java/org/jruby/RubyMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.MethodBlockBody;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.PositionAware;
import org.jruby.runtime.Signature;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.backtrace.TraceType;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.CacheEntry;

Expand Down Expand Up @@ -282,14 +280,14 @@ public IRubyObject inspect() {
if (mklass.isSingleton()) {
IRubyObject attached = ((MetaClass) mklass).getAttached();
if (receiver == null) {
str.cat19(inspect(context, mklass).convertToString());
str.catWithCodeRange(inspect(context, mklass).convertToString());
} else if (receiver == attached) {
str.cat19(inspect(context, attached).convertToString());
str.catWithCodeRange(inspect(context, attached).convertToString());
sharp = ".";
} else {
str.cat19(inspect(context, receiver).convertToString());
str.catWithCodeRange(inspect(context, receiver).convertToString());
str.catString("(");
str.cat19(inspect(context, attached).convertToString());
str.catWithCodeRange(inspect(context, attached).convertToString());
str.catString(")");
sharp = ".";
}
Expand Down
13 changes: 7 additions & 6 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,10 @@ private RubyString calculateRubyName() {
RubyString fullName = runtime.newString(); // newString creates empty ByteList which ends up as
fullName.setEncoding(USASCIIEncoding.INSTANCE); // ASCII-8BIT. 8BIT is unfriendly to string concats.
for (RubyString parent: parents) {
fullName.cat19(parent).cat19(colons);
RubyString rubyString = fullName.catWithCodeRange(parent);
rubyString.catWithCodeRange(colons);
}
fullName.cat19(rubyBaseName());
fullName.catWithCodeRange(rubyBaseName());

fullName.setFrozen(true);

Expand Down Expand Up @@ -2786,9 +2787,9 @@ public RubyString to_s() {
RubyString buffer = runtime.newString("#<Class:");

if (attached instanceof RubyModule) {
buffer.cat19(attached.inspect().convertToString());
buffer.catWithCodeRange(attached.inspect().convertToString());
} else if (attached != null) {
buffer.cat19((RubyString) attached.anyToString());
buffer.catWithCodeRange((RubyString) attached.anyToString());
}
buffer.cat('>', buffer.getEncoding());

Expand All @@ -2800,9 +2801,9 @@ public RubyString to_s() {
if (refinedClass != null) {
RubyString buffer = runtime.newString("#<refinement:");

buffer.cat19(refinedClass.inspect().convertToString());
buffer.catWithCodeRange(refinedClass.inspect().convertToString());
buffer.cat('@', buffer.getEncoding());
buffer.cat19((definedAt.inspect().convertToString()));
buffer.catWithCodeRange((definedAt.inspect().convertToString()));
buffer.cat('>', buffer.getEncoding());

return buffer;
Expand Down
29 changes: 15 additions & 14 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,8 @@ public final int catWithCodeRange(ByteList other, int codeRange) {
}

public final RubyString catString(String str) {
cat19(encodeBytelist(str, getEncoding()), CR_UNKNOWN);
ByteList other = encodeBytelist(str, getEncoding());
catWithCodeRange(other, CR_UNKNOWN);
return this;
}

Expand Down Expand Up @@ -2381,7 +2382,7 @@ public IRubyObject insert(ThreadContext context, IRubyObject indexArg, IRubyObje
int index = RubyNumeric.num2int(indexArg);
if (index == -1) {
modifyCheck();
return cat19(str);
return catWithCodeRange(str);
}
if (index < 0) index++;
replaceInternal19(index, 0, str);
Expand Down Expand Up @@ -2676,18 +2677,18 @@ public RubyString append(IRubyObject other) {
modifyCheck();

if (other instanceof RubyFloat) {
return cat19((RubyString) ((RubyFloat) other).to_s());
return catWithCodeRange((RubyString) ((RubyFloat) other).to_s());
} else if (other instanceof RubySymbol) {
cat19(((RubySymbol) other).getBytes(), CR_UNKNOWN);
catWithCodeRange(((RubySymbol) other).getBytes(), CR_UNKNOWN);
return this;
}

return cat19(other.convertToString());
return catWithCodeRange(other.convertToString());
}

public RubyString append(RubyString other) {
modifyCheck();
return cat19(other);
return catWithCodeRange(other);
}

@Deprecated
Expand All @@ -2705,19 +2706,19 @@ public RubyString appendAsDynamicString(IRubyObject other) {
modifyCheck();

if (other instanceof RubyFloat) {
return cat19((RubyString) ((RubyFloat) other).to_s());
return catWithCodeRange((RubyString) ((RubyFloat) other).to_s());
} else if (other instanceof RubySymbol) {
cat19(((RubySymbol) other).getBytes(), 0);
catWithCodeRange(((RubySymbol) other).getBytes(), 0);
return this;
}

return cat19(other.asString());
return catWithCodeRange(other.asString());
}

// NOTE: append(RubyString) should pbly just do the encoding aware cat
final RubyString append19(RubyString other) {
modifyCheck();
return cat19(other);
return catWithCodeRange(other);
}

/** rb_str_concat
Expand Down Expand Up @@ -2745,7 +2746,7 @@ public RubyString concatSingle(ThreadContext context, IRubyObject other) {
}
if (other instanceof RubyFloat) {
modifyCheck();
return cat19((RubyString) ((RubyFloat) other).to_s());
return catWithCodeRange((RubyString) ((RubyFloat) other).to_s());
}
if (other instanceof RubySymbol) throw context.runtime.newTypeError("can't convert Symbol into String");

Expand Down Expand Up @@ -2776,7 +2777,7 @@ public RubyString concat(ThreadContext context, IRubyObject[] objs) {
tmp.concatSingle(context, obj);
}

cat19(tmp);
catWithCodeRange(tmp);
}

return this;
Expand Down Expand Up @@ -3321,7 +3322,7 @@ private IRubyObject gsubCommon(ThreadContext context, Block block, RubyString re

int len = begz - offset;
if (len != 0) dest.cat(spBytes, cp, len, str_enc);
dest.cat19(val);
dest.catWithCodeRange(val);
offset = endz;
if (begz == endz) {
if (spLen <= endz) break;
Expand Down Expand Up @@ -3413,7 +3414,7 @@ private IRubyObject gsubCommon(ThreadContext context, Block block, RubyString re

int len = begz - offset;
if (len != 0) dest.cat(spBytes, cp, len, str_enc);
dest.cat19(val);
dest.catWithCodeRange(val);
offset = endz;
if (begz == endz) {
if (spLen <= endz) break;
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,12 @@ else if (first != '#') {
}
RubySymbol slot = (RubySymbol) member.eltInternal(i);
if (slot.validLocalVariableName() || slot.validConstantName()) {
buffer.cat19(RubyString.objAsString(context, slot));
buffer.catWithCodeRange(RubyString.objAsString(context, slot));
} else {
buffer.cat19(((RubyString) slot.inspect(context)));
buffer.catWithCodeRange(((RubyString) slot.inspect(context)));
}
buffer.cat('=');
buffer.cat19(inspect(context, values[i]));
buffer.catWithCodeRange(inspect(context, values[i]));
}

buffer.cat('>');
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ext/set/RubySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ private void inspectSet(final ThreadContext context, final RubyString str) {
final RubyString s = inspect(context, elem);
if ( notFirst ) str.cat((byte) ',').cat((byte) ' ');
else str.setEncoding( s.getEncoding() ); notFirst = true;
str.cat19( s );
str.catWithCodeRange(s);
}

str.cat((byte) '}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public RubyString inspect(ThreadContext context) {
} else {
buf.setEncoding(s.getEncoding());
}
buf.cat19(s);
buf.catWithCodeRange(s);
}
RubyStringBuilder.cat(runtime, buf, END_BRACKET); // ]
} finally {
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.jruby.anno.JRubyMethod;
import org.jruby.exceptions.RaiseException;
import org.jruby.javasupport.JavaUtil;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
Expand Down Expand Up @@ -136,7 +135,7 @@ public IRubyObject inspect(ThreadContext context) {
} else {
try {
runtime.registerInspecting(map);
buf.cat19(inspectHash(context));
buf.catWithCodeRange(inspectHash(context));
} finally {
runtime.unregisterInspecting(map);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/javasupport/ext/JavaLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ public static IRubyObject inspect(final ThreadContext context, final IRubyObject

RubyString buf = inspectPrefix(context, self.getMetaClass());
RubyStringBuilder.cat(context.runtime, buf, SPACE);
buf.cat19(RubyString.newString(context.runtime, str).inspect());
buf.catWithCodeRange(RubyString.newString(context.runtime, str).inspect());
RubyStringBuilder.cat(context.runtime, buf, GT); // >

return buf;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/javasupport/ext/JavaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static void inspectElements(final ThreadContext context, final RubyString buf, f
} else {
buf.setEncoding(s.getEncoding());
}
buf.cat19(s);
buf.catWithCodeRange(s);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jruby.specialized;

import org.jcodings.Encoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.Ruby;
import org.jruby.RubyArray;
Expand Down Expand Up @@ -141,7 +140,7 @@ protected IRubyObject inspectAry(ThreadContext context) {

RubyString s = inspect(context, value);
EncodingUtils.encAssociateIndex(str, s.getEncoding());
str.cat19(s);
str.catWithCodeRange(s);

str.cat((byte) ']');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jruby.specialized;

import org.jcodings.Encoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.Ruby;
import org.jruby.RubyArray;
Expand Down Expand Up @@ -158,12 +157,12 @@ protected IRubyObject inspectAry(ThreadContext context) {
RubyString s1 = inspect(context, car);
RubyString s2 = inspect(context, cdr);
EncodingUtils.encAssociateIndex(str, s1.getEncoding());
str.cat19(s1);
str.catWithCodeRange(s1);

ByteList bytes = str.getByteList();
bytes.append((byte) ',').append((byte) ' ');

str.cat19(s2);
str.catWithCodeRange(s2);

str.cat((byte) ']');

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/util/Inspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public static RubyString inspectPrefixTypeOnly(final ThreadContext context, fina
RubyString name = RubyStringBuilder.types(context, type);
// minimal: "#<Object:0x5a1c0542>"
RubyString buf = RubyString.newStringLight(context.runtime, 2 + name.length() + 3 + 8 + 1, USASCIIEncoding.INSTANCE);
buf.cat('#').cat('<').cat19(name);
RubyString rubyString = buf.cat('#').cat('<');
rubyString.catWithCodeRange(name);
return buf;
}

Expand Down
Loading

0 comments on commit 2476e8b

Please sign in to comment.