Skip to content

Commit a8f888c

Browse files
committed
minor performance tweaks to mmap module
1 parent 5dbb0a5 commit a8f888c

File tree

1 file changed

+10
-5
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util

1 file changed

+10
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/ChannelNodes.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ public abstract static class WriteToChannelNode extends WriteToChannelBaseNode {
298298

299299
@Specialization
300300
int writeSeekable(SeekableByteChannel channel, SequenceStorage s, int len,
301+
@Cached BranchProfile limitProfile,
302+
@Cached("createBinaryProfile()") ConditionProfile maxSizeProfile,
301303
@Cached PRaiseNode raise) {
302304
long availableSize;
303305
try {
@@ -306,31 +308,34 @@ int writeSeekable(SeekableByteChannel channel, SequenceStorage s, int len,
306308
gotException.enter();
307309
throw raise.raise(OSError, e);
308310
}
309-
if (availableSize > MAX_WRITE) {
311+
if (maxSizeProfile.profile(availableSize > MAX_WRITE)) {
310312
availableSize = MAX_WRITE;
311313
}
312314
int sz = (int) Math.min(availableSize, len);
313-
return writeWritable(channel, s, sz, raise);
314-
315+
return writeWritable(channel, s, sz, limitProfile, raise);
315316
}
316317

317318
@Specialization
318319
int writeWritable(WritableByteChannel channel, SequenceStorage s, int len,
320+
@Cached BranchProfile limitProfile,
319321
@Cached PRaiseNode raise) {
320322
ByteBuffer src = allocateBuffer(getBytes(s));
321323
if (src.remaining() > len) {
324+
limitProfile.enter();
322325
src.limit(len);
323326
}
324327
return writeFromBuffer(channel, src, raise);
325328
}
326329

327330
@Specialization
328331
int writeGeneric(Channel channel, SequenceStorage s, int len,
332+
@Cached BranchProfile limitProfile,
333+
@Cached("createBinaryProfile()") ConditionProfile maxSizeProfile,
329334
@Cached PRaiseNode raise) {
330335
if (channel instanceof SeekableByteChannel) {
331-
return writeSeekable((SeekableByteChannel) channel, s, len, raise);
336+
return writeSeekable((SeekableByteChannel) channel, s, len, limitProfile, maxSizeProfile, raise);
332337
} else if (channel instanceof ReadableByteChannel) {
333-
return writeWritable((WritableByteChannel) channel, s, len, raise);
338+
return writeWritable((WritableByteChannel) channel, s, len, limitProfile, raise);
334339
} else {
335340
throw raise.raise(OSError, "file not opened for reading");
336341
}

0 commit comments

Comments
 (0)