From 11d1ba757bb8c7446e6082c358f440491f2b8e47 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Tue, 7 Nov 2023 20:35:42 -0600 Subject: [PATCH] Avoid transient array that is not needed --- .../java/org/jruby/util/SunSignalFacade.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/jruby/util/SunSignalFacade.java b/core/src/main/java/org/jruby/util/SunSignalFacade.java index 8f89d29610c..759b8b6b294 100644 --- a/core/src/main/java/org/jruby/util/SunSignalFacade.java +++ b/core/src/main/java/org/jruby/util/SunSignalFacade.java @@ -30,6 +30,7 @@ import org.jruby.Ruby; import org.jruby.RubyArray; +import org.jruby.RubyBoolean; import org.jruby.RubyFixnum; import org.jruby.RubyModule; import org.jruby.RubyProc; @@ -183,7 +184,8 @@ private IRubyObject trap(final Ruby runtime, final String signalName, final Sign } private static IRubyObject getSignalResult(final Ruby runtime, final SignalHandler oldHandler, boolean handled) { - IRubyObject[] retVals = new IRubyObject[] { null, runtime.newBoolean(handled) }; + RubyBoolean handledBoolean = runtime.newBoolean(handled); + IRubyObject ret = null; BlockCallback callback = null; if (oldHandler instanceof JRubySignalHandler) { @@ -191,26 +193,26 @@ private static IRubyObject getSignalResult(final Ruby runtime, final SignalHandl if (jsHandler.blockCallback != null) { callback = jsHandler.blockCallback; } else { - retVals[0] = jsHandler.block; - return RubyArray.newArrayMayCopy(runtime, retVals); + ret = jsHandler.block; + return RubyArray.newArray(runtime, ret, handledBoolean); } } if (callback == null) { if (oldHandler == SignalHandler.SIG_DFL) { - retVals[0] = runtime.newString("SYSTEM_DEFAULT"); + ret = runtime.newString("SYSTEM_DEFAULT"); } else if (oldHandler == IGNORE) { - retVals[0] = runtime.newString("IGNORE"); + ret = runtime.newString("IGNORE"); } else { - retVals[0] = runtime.newString("DEFAULT"); + ret = runtime.newString("DEFAULT"); } } else { Block block = CallBlock.newCallClosure(runtime.getCurrentContext(), runtime.getModule("Signal"), Signature.NO_ARGUMENTS, callback); - retVals[0] = RubyProc.newProc(runtime, block, Block.Type.PROC); + ret = RubyProc.newProc(runtime, block, Block.Type.PROC); } - return RubyArray.newArrayMayCopy(runtime, retVals); + return RubyArray.newArrayMayCopy(runtime, ret, handledBoolean); } }// SunSignalFacade