Skip to content

Commit 5b112fc

Browse files
committed
Use cached Ptr instances per-OpenFile
These Ptr instances are only ever read or written under lock, so we can share them and reduce allocation along this hot path.
1 parent 1736fce commit 5b112fc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

core/src/main/java/org/jruby/util/io/OpenFile.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ public static class Buffer {
154154

155155
protected volatile Set<RubyThread> blockingThreads;
156156

157+
private Ptr spPtr = new Ptr();
158+
private Ptr dpPtr = new Ptr();
159+
157160
public void clearStdio() {
158161
stdio_file = null;
159162
}
@@ -1202,8 +1205,8 @@ else if (cbuf.off + cbuf.len == cbuf.capa) {
12021205

12031206
cbuf_len0 = cbuf.len;
12041207

1205-
Ptr spPtr = new Ptr();
1206-
Ptr dpPtr = new Ptr();
1208+
spPtr.p = 0;
1209+
dpPtr.p = 0;
12071210

12081211
while (true) {
12091212
ss = spPtr.p = rbuf.off;
@@ -2359,11 +2362,11 @@ public SocketChannel socketChannel() {
23592362
IRubyObject finishWriteconv(ThreadContext context, boolean noalloc) {
23602363
byte[] dsBytes;
23612364
int ds, de;
2362-
Ptr dpPtr = new Ptr();
23632365
EConvResult res;
23642366

23652367
boolean locked = lock();
23662368
try {
2369+
dpPtr.p = 0;
23672370
if (wbuf.ptr == null) {
23682371
byte[] buf = new byte[1024];
23692372
long r;

0 commit comments

Comments
 (0)