|
10 | 10 | import java.io.ByteArrayOutputStream; |
11 | 11 | import java.io.IOException; |
12 | 12 | import java.io.InputStream; |
13 | | -import java.lang.invoke.MethodHandle; |
14 | | -import java.lang.invoke.MethodHandles; |
15 | | -import java.lang.invoke.MethodType; |
16 | 13 | import java.lang.reflect.InvocationTargetException; |
17 | 14 | import java.lang.reflect.Method; |
18 | 15 |
|
|
27 | 24 | import org.jruby.rack.servlet.RewindableInputStream; |
28 | 25 | import org.jruby.rack.util.ExceptionUtils; |
29 | 26 | import org.jruby.runtime.Block; |
30 | | -import org.jruby.runtime.Helpers; |
31 | 27 | import org.jruby.runtime.ObjectAllocator; |
32 | 28 | import org.jruby.runtime.ThreadContext; |
33 | 29 | import org.jruby.runtime.builtin.IRubyObject; |
|
42 | 38 | */ |
43 | 39 | @SuppressWarnings("serial") |
44 | 40 | public class Input extends RubyObject { |
45 | | - private static final MethodHandle CONCAT_WITH_CODERANGE; |
46 | | - |
47 | | - static { |
48 | | - // set up coderange-aware concat that works with the new catWithCodeRange as well as earlier JRuby without it. |
49 | | - // TODO: remove and replace with direct call once 9.3 is fully unsupported |
50 | | - MethodHandle catWithCR = null; |
51 | | - MethodHandles.Lookup lookup = MethodHandles.lookup(); |
52 | | - try { |
53 | | - catWithCR = lookup.findVirtual(RubyString.class, "catWithCodeRange", MethodType.methodType(int.class, ByteList.class, int.class)); |
54 | | - } catch (NoSuchMethodException | IllegalAccessException e) { |
55 | | - try { |
56 | | - catWithCR = lookup.findVirtual(RubyString.class, "cat19", MethodType.methodType(int.class, ByteList.class, int.class)); |
57 | | - } catch (Exception t) { |
58 | | - Helpers.throwException(t); |
59 | | - } |
60 | | - } |
61 | | - CONCAT_WITH_CODERANGE = catWithCR; |
62 | | - } |
63 | 41 |
|
64 | 42 | static final ObjectAllocator ALLOCATOR = Input::new; |
65 | 43 |
|
@@ -166,12 +144,7 @@ public IRubyObject read(final ThreadContext context, final IRubyObject[] args) { |
166 | 144 | if ( bytes != null ) { |
167 | 145 | if ( buffer != null ) { |
168 | 146 | buffer.clear(); |
169 | | - try { |
170 | | - int unused = (int) CONCAT_WITH_CODERANGE.invokeExact(buffer, new ByteList(bytes, false), StringSupport.CR_UNKNOWN); |
171 | | - } catch (Throwable t) { |
172 | | - Helpers.throwException(t); |
173 | | - } |
174 | | - |
| 147 | + buffer.catWithCodeRange(new ByteList(bytes, false), StringSupport.CR_UNKNOWN); |
175 | 148 | return buffer; |
176 | 149 | } |
177 | 150 | return context.runtime.newString(new ByteList(bytes, false)); |
|
0 commit comments