Skip to content

Commit

Permalink
cache method reference to reduce liklihood of allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
epickrram committed Nov 9, 2017
1 parent aff8dfe commit 2091c3d
Showing 1 changed file with 6 additions and 3 deletions.
Expand Up @@ -26,6 +26,9 @@ final class TableDirectoryListing implements DirectoryListing {
private final TableStore tableStore;
private final Path queuePath;
private final ToIntFunction<File> fileToCycleFunction;
private final IntSupplier getMaxCycleValueMethodRef = this::getMaxCycleValue;
private final IntSupplier getMinCycleValueMethodRef = this::getMinCycleValue;
private final IntSupplier refreshIndexMethodRef = this::refreshIndex;
private volatile LongValue maxCycleValue;
private volatile LongValue minCycleValue;
private volatile LongValue lock;
Expand Down Expand Up @@ -64,7 +67,7 @@ public void refresh() {
if (readOnly) {
return;
}
tryWithLock(this::refreshIndex);
tryWithLock(refreshIndexMethodRef);
}

@Override
Expand All @@ -86,15 +89,15 @@ public int getMaxCreatedCycle() {
if (readOnly) {
return getMaxCycleValue();
}
return tryWithLock(this::getMaxCycleValue);
return tryWithLock(getMaxCycleValueMethodRef);
}

@Override
public int getMinCreatedCycle() {
if (readOnly) {
return getMinCycleValue();
}
return tryWithLock(this::getMinCycleValue);
return tryWithLock(getMinCycleValueMethodRef);
}

@Override
Expand Down

0 comments on commit 2091c3d

Please sign in to comment.