File tree Expand file tree Collapse file tree
src/main/java/com/beaudoin/jmm Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3434public final class Cacheable {
3535
3636 private static final Map <Integer , MemoryBuffer > bufferCache = new HashMap <>();
37- private static final Function <Integer , MemoryBuffer > cachedFunction = MemoryBuffer ::new ;
37+ private static final Function <Integer , MemoryBuffer > butterCreate = MemoryBuffer ::new ;
38+
39+ private static final Map <Integer , byte []> arrayCache = new HashMap <>();
40+ private static final Function <Integer , byte []> arrayCreate = byte []::new ;
41+
3842 private static final Pointer cachedPointer = new Pointer (0 );
3943 public static final IntByReference INT_BY_REF = new IntByReference ();
4044
4145 public static MemoryBuffer buffer (int size ) {
42- return bufferCache .computeIfAbsent (size , cachedFunction );
46+ return bufferCache .computeIfAbsent (size , butterCreate );
47+ }
48+
49+ public static byte [] array (int size ) {
50+ return arrayCache .computeIfAbsent (size , arrayCreate );
4351 }
4452
4553 public static Pointer pointer (long address ) {
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ public int size() {
111111 }
112112
113113 public byte [] array () {
114- byte [] data = new byte [ size ] ;
114+ byte [] data = Cacheable . array ( size ) ;
115115 get (data );
116116 return data ;
117117 }
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ default double readDouble(long address) {
5151 }
5252
5353 default String readString (long address , int length ) {
54- byte [] bytes = new byte [ length ] ;
54+ byte [] bytes = Cacheable . array ( length ) ;
5555 read (address , bytes .length ).get (bytes );
5656 return Strings .transform (bytes );
5757 }
You can’t perform that action at this time.
0 commit comments