boolean taint = isTaint() || sep.isTaint();
long len = 1;
for (int i = begin; i < begin + realLength; i++) {
IRubyObject value;
try {
value = values[i];
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
return runtime.newString("");
}
IRubyObject tmp = value.checkStringType();
len += tmp.isNil() ? 10 : ((RubyString) tmp).getByteList().length();
}
RubyString strSep = null;
if (!sep.isNil()) {
sep = strSep = sep.convertToString();
len += strSep.getByteList().length() * (realLength - 1);
}
ByteList buf = new ByteList((int)len);
for (int i = begin; i < begin + realLength; i++) {
IRubyObject tmp;
try {
tmp = values[i];
} catch (ArrayIndexOutOfBoundsException e) {
concurrentModification();
return runtime.newString("");
}
if (tmp instanceof RubyString) {
// do nothing
} else if (tmp instanceof RubyArray) {
if (runtime.isInspecting(tmp)) {
tmp = runtime.newString("[...]");
} else {
tmp = inspectJoin(context, (RubyArray)tmp, sep);
}
} else {
tmp = RubyString.objAsString(context, tmp);
}
if (i > begin && !sep.isNil()) buf.append(strSep.getByteList());
buf.append(tmp.asString().getByteList());
if (tmp.isTaint()) taint = true;
}
RubyString result = runtime.newString(buf);
if (taint) result.setTaint(true);