From 0374994f9f4a636f4fd1bcac7be5f3a2c2925b3d Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 12 Nov 2023 13:51:10 +0100 Subject: [PATCH] redone last commit --- .../com/troblecodings/signals/handler/SignalStateFile.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/handler/SignalStateFile.java b/src/main/java/com/troblecodings/signals/handler/SignalStateFile.java index bceb62e4c..9e574b949 100644 --- a/src/main/java/com/troblecodings/signals/handler/SignalStateFile.java +++ b/src/main/java/com/troblecodings/signals/handler/SignalStateFile.java @@ -71,6 +71,9 @@ private static long hash(final BlockPos pos) { @Nullable public synchronized SignalStatePos find(final BlockPos pos) { + final SignalStatePos cachePos = posCache.get(pos); + if (cachePos != null) + return cachePos; return (SignalStatePos) internalFind(pos, (stream, blockPos, offset, file) -> new SignalStatePos(file, offset), "r"); } @@ -82,7 +85,7 @@ public synchronized SignalStatePos deleteIndex(final BlockPos pos) { stream.seek(pointer - 16); stream.writeLong(0); stream.writeLong(0); - // TODO posCache.remove(pos); + posCache.remove(pos); return new SignalStatePos(file, offset); } catch (final IOException e) { e.printStackTrace(); @@ -119,7 +122,7 @@ private synchronized Object internalFind(final BlockPos pos, final InternalFunct if (currentOffset == hashOffset) continue nextFile; // Nothing found } while (!pos.equals(currenPosition)); - // TODO posCache.put(pos, new SignalStatePos(counter, offset)); + posCache.put(pos, new SignalStatePos(counter, offset)); return function.apply(stream, currenPosition, offset, counter); } }