Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ public ClonedChunkSectionCache(Level world) {

public synchronized void cleanup() {
this.time = getMonotonicTimeSource();
this.positionToEntry.values()
.removeIf(entry -> this.time > (entry.getLastUsedTimestamp() + MAX_CACHE_DURATION));

// The map is kept in order of last use, as acquire() moves each entry it returns to the end and stamps it with
// the current time. The expired entries are therefore always at the front, so stop at the first one which has
// not expired rather than checking every entry.
var iterator = this.positionToEntry.values().iterator();

while (iterator.hasNext() && this.time > (iterator.next().getLastUsedTimestamp() + MAX_CACHE_DURATION)) {
iterator.remove();
}
}

@Nullable
Expand Down
Loading