|
30 | 30 |
|
31 | 31 | abstract class Scanner implements AutoCloseable { |
32 | 32 | private static final Cleaner CLEANER = Cleaner.create(); |
33 | | - |
34 | 33 | private long bufferCapacity = 1024L; // 1KB default buffer size |
35 | 34 | private int bufferLength; |
36 | | - private Arena dataArena = Arena.ofConfined(); |
| 35 | + private Arena dataArena = Arena.ofShared(); |
37 | 36 | private MemorySegment dataSegment = dataArena.allocate(bufferCapacity); |
38 | | - protected final Arena arena = Arena.ofConfined(); |
| 37 | + protected final Arena arena = Arena.ofShared(); |
39 | 38 | protected final Database database; |
40 | | - private OnMatchEventHandler handler; |
41 | 39 | protected final MemorySegment scratch; |
42 | | - protected final MemorySegment funcPtr = VectorscanMatchEventHandler.allocate(new CallHandlerOnMatch(), arena); |
43 | | - private final CleanupState cleanupState; |
| 40 | + private final CallHandlerOnMatch callHandler = new CallHandlerOnMatch(); |
| 41 | + protected MemorySegment funcPtr = VectorscanMatchEventHandler.allocate(callHandler, arena); |
| 42 | + ; |
| 43 | + protected final CleanupState cleanupState; |
44 | 44 | private final Cleaner.Cleanable cleanable; |
45 | 45 |
|
46 | | - private static final class CleanupState implements Runnable { |
| 46 | + static class CallHandlerOnMatch implements VectorscanMatchEventHandler.Function { |
| 47 | + OnMatchEventHandler handler; |
| 48 | + |
| 49 | + @Override |
| 50 | + public int apply(int id, long from, long to, int flags, MemorySegment context) { |
| 51 | + return handler.onMatch(id, from, to, flags) ? 0 : 1; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + protected static final class CleanupState implements Runnable { |
47 | 56 | private final MemorySegment scratch; |
48 | 57 | private final Arena arena; // manages lifetime of internal scratch space. |
49 | 58 | private Arena dataArena; // manages lifetime of internal data segment. |
@@ -76,17 +85,12 @@ public void run() { |
76 | 85 | } |
77 | 86 |
|
78 | 87 | protected void setHandler(OnMatchEventHandler handler) { |
79 | | - this.handler = handler; |
80 | | - } |
81 | | - |
82 | | - protected class CallHandlerOnMatch implements VectorscanMatchEventHandler.Function { |
83 | | - @Override |
84 | | - public int apply(int id, long from, long to, int flags, MemorySegment context) { |
85 | | - return handler.onMatch(id, from, to, flags) ? 0 : 1; |
86 | | - } |
| 88 | + this.callHandler.handler = handler; |
87 | 89 | } |
88 | 90 |
|
89 | 91 | protected Scanner(Database database) { |
| 92 | + CallHandlerOnMatch callHandler = new CallHandlerOnMatch(); |
| 93 | + |
90 | 94 | this.database = database; |
91 | 95 |
|
92 | 96 | // allocate scratch space |
@@ -117,7 +121,7 @@ protected void setBuffer(ByteBuffer input) { |
117 | 121 |
|
118 | 122 | private void resizeBuffer(long newSize) { |
119 | 123 | dataArena.close(); |
120 | | - dataArena = Arena.ofConfined(); |
| 124 | + dataArena = Arena.ofShared(); |
121 | 125 | cleanupState.setDataArena(dataArena); |
122 | 126 | dataSegment = dataArena.allocate(newSize); |
123 | 127 | bufferCapacity = newSize; |
|
0 commit comments