Skip to content

Commit

Permalink
Fix performance warnings in FilePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Mar 16, 2022
1 parent 7b99bfa commit e905b5d
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public List<? extends NodeFactory<? extends AbstractPrimitiveNode>> getFactories

protected abstract static class AbstractFilePluginPrimitiveNode extends AbstractPrimitiveNode {

@TruffleBoundary(transferToInterpreterOnException = false)
protected static final SeekableByteChannel getChannelOrPrimFail(final PointersObject handle) {
final Object hiddenObject = getChannelOrNil(handle);
if (hiddenObject instanceof SeekableByteChannel) {
Expand Down Expand Up @@ -348,16 +349,16 @@ protected abstract static class PrimFileCloseNode extends AbstractFilePluginPrim
@Specialization(guards = "!isStdioFileDescriptor(fd)")
protected static final Object doClose(final Object receiver, final PointersObject fd) {
final Object channelOrNil = getChannelOrNil(fd);
if (channelOrNil instanceof SeekableByteChannel) {
closeFailsafe((SeekableByteChannel) channelOrNil);
if (channelOrNil != NilObject.SINGLETON) {
closeFailsafe(channelOrNil);
}
return receiver;
}

@TruffleBoundary
private static void closeFailsafe(final SeekableByteChannel channel) {
private static void closeFailsafe(final Object channel) {
try {
channel.close();
((SeekableByteChannel) channel).close();
} catch (final IOException e) {
log("Failed to close file", e);
}
Expand Down

0 comments on commit e905b5d

Please sign in to comment.