more headless speed

This commit is contained in:
Julian Krings 2024-08-23 15:05:45 +02:00
parent 3bffe4cc7e
commit b1e87afc93
2 changed files with 12 additions and 5 deletions

View File

@ -33,7 +33,7 @@ public class SyncChunkDataHunkHolder extends ArrayHunk<BlockData> {
}
public void apply() {
for (int i = 0; i < getHeight(); i++) {
for (int i = getHeight()-1; i >= 0; i--) {
for (int j = 0; j < getWidth(); j++) {
for (int k = 0; k < getDepth(); k++) {
BlockData b = super.getRaw(j, i, k);

View File

@ -45,14 +45,19 @@ public final class RegionFileStorage implements AutoCloseable {
this.sync = sync;
}
public synchronized RegionFile getRegionFile(ChunkPos chunkPos, boolean existingOnly) throws IOException {
public RegionFile getRegionFile(ChunkPos chunkPos, boolean existingOnly) throws IOException {
long id = ChunkPos.asLong(chunkPos.getRegionX(), chunkPos.getRegionZ());
RegionFile regionFile = this.regionCache.getAndMoveToFirst(id);
RegionFile regionFile;
synchronized (this.regionCache) {
regionFile = this.regionCache.getAndMoveToFirst(id);
}
if (regionFile != null) {
return regionFile;
} else {
if (this.regionCache.size() >= 256) {
this.regionCache.removeLast().close();
synchronized (this.regionCache) {
this.regionCache.removeLast().close();
}
}
FileUtil.createDirectoriesSafe(this.folder);
@ -61,7 +66,9 @@ public final class RegionFileStorage implements AutoCloseable {
return null;
} else {
regionFile = new RegionFile(path, this.folder, this.sync);
this.regionCache.putAndMoveToFirst(id, regionFile);
synchronized (this.regionCache) {
this.regionCache.putAndMoveToFirst(id, regionFile);
}
return regionFile;
}
}