|
55 | 55 | import org.jruby.util.io.ModeFlags;
|
56 | 56 | import org.jruby.util.io.OpenFile;
|
57 | 57 |
|
| 58 | +import java.lang.invoke.MethodHandle; |
| 59 | +import java.lang.invoke.MethodHandles; |
| 60 | +import java.lang.invoke.MethodType; |
58 | 61 | import java.util.Arrays;
|
59 | 62 |
|
60 | 63 | import static org.jruby.RubyEnumerator.enumeratorize;
|
@@ -1270,6 +1273,23 @@ public IRubyObject write(ThreadContext context, IRubyObject[] args) {
|
1270 | 1273 | return RubyFixnum.newFixnum(runtime, len);
|
1271 | 1274 | }
|
1272 | 1275 |
|
| 1276 | + private static final MethodHandle CAT_WITH_CODE_RANGE; |
| 1277 | + |
| 1278 | + static { |
| 1279 | + MethodHandle cat; |
| 1280 | + try { |
| 1281 | + cat = MethodHandles.publicLookup().findVirtual(RubyString.class, "catWithCodeRange", MethodType.methodType(RubyString.class, RubyString.class)); |
| 1282 | + } catch (NoSuchMethodException | IllegalAccessException ex) { |
| 1283 | + try { |
| 1284 | + cat = MethodHandles.publicLookup().findVirtual(RubyString.class, "cat19", MethodType.methodType(RubyString.class, RubyString.class)); |
| 1285 | + } catch (NoSuchMethodException | IllegalAccessException ex2) { |
| 1286 | + throw new ExceptionInInitializerError(ex2); |
| 1287 | + } |
| 1288 | + } |
| 1289 | + |
| 1290 | + CAT_WITH_CODE_RANGE = cat; |
| 1291 | + } |
| 1292 | + |
1273 | 1293 | // MRI: strio_write
|
1274 | 1294 | private long stringIOWrite(ThreadContext context, Ruby runtime, IRubyObject arg) {
|
1275 | 1295 | checkWritable();
|
@@ -1299,7 +1319,11 @@ private long stringIOWrite(ThreadContext context, Ruby runtime, IRubyObject arg)
|
1299 | 1319 | if (enc == EncodingUtils.ascii8bitEncoding(runtime) || encStr == EncodingUtils.ascii8bitEncoding(runtime)) {
|
1300 | 1320 | EncodingUtils.encStrBufCat(runtime, ptr.string, strByteList, enc);
|
1301 | 1321 | } else {
|
1302 |
| - ptr.string.cat19(str); |
| 1322 | + try { |
| 1323 | + RubyString unused = (RubyString) CAT_WITH_CODE_RANGE.invokeExact(ptr.string, str); |
| 1324 | + } catch (Throwable t) { |
| 1325 | + throw new RuntimeException(t); |
| 1326 | + } |
1303 | 1327 | }
|
1304 | 1328 | } else {
|
1305 | 1329 | strioExtend(ptr.pos, len);
|
|
0 commit comments