Skip to content

Commit

Permalink
Avoid transient array that is not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 8, 2023
1 parent 8fa47d8 commit 1399298
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions core/src/main/java/org/jruby/util/SunSignalFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -183,34 +184,35 @@ 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) {
JRubySignalHandler jsHandler = (JRubySignalHandler) oldHandler;
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

0 comments on commit 1399298

Please sign in to comment.