<commit_before>package me.nallar.patched.storage;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import cpw.mods.fml.common.FMLLog;
import me.nallar.patched.annotation.FakeExtend;
import me.nallar.tickthreading.Log;
import me.nallar.tickthreading.minecraft.TickThreading;
import me.nallar.tickthreading.minecraft.storage.RegionFileCache;
import me.nallar.tickthreading.patcher.Declare;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.LongHashMap;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.MinecraftException;
import net.minecraft.world.NextTickListEntry;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.NibbleArray;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import net.minecraft.world.chunk.storage.AnvilChunkLoaderPending;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraft.world.chunk.storage.IChunkLoader;
import net.minecraft.world.storage.IThreadedFileIO;
import net.minecraft.world.storage.ThreadedFileIOBase;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.ChunkDataEvent;

@FakeExtend
public abstract class ThreadedChunkLoader extends AnvilChunkLoader implements IThreadedFileIO, IChunkLoader {
	private final java.util.LinkedHashMap<ChunkCoordIntPair, AnvilChunkLoaderPending> pendingSaves = new java.util.LinkedHashMap<ChunkCoordIntPair, AnvilChunkLoaderPending>(); // Spigot
	private final LongHashMap inProgressSaves = new LongHashMap();
	private final Object syncLockObject = new Object();
	public final File chunkSaveLocation;
	private final Cache<Long, NBTTagCompound> chunkCache;
	public final RegionFileCache regionFileCache;

	public ThreadedChunkLoader(File par1File) {
		super(par1File);
		this.chunkSaveLocation = par1File;
		chunkCache = CacheBuilder.newBuilder().maximumSize(TickThreading.instance.chunkCacheSize).build();
		regionFileCache = new RegionFileCache(chunkSaveLocation);
	}

	public boolean chunkExists(World world, int i, int j) {
		ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);

		synchronized (this.syncLockObject) {
			if (pendingSaves.containsKey(chunkcoordintpair)) {
				return true;
			}
		}

		return regionFileCache.get(i, j).isChunkSaved(i & 31, j & 31);
	}

	@Override
	public Chunk loadChunk(World world, int x, int z) {
		NBTTagCompound nbttagcompound;
		ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(x, z);

		synchronized (this.syncLockObject) {
			AnvilChunkLoaderPending pendingchunktosave = pendingSaves.get(chunkcoordintpair);

			if (pendingchunktosave == null) {
				long hash = hash(x, z);
				nbttagcompound = (NBTTagCompound) inProgressSaves.getValueByKey(hash);
				if (nbttagcompound == null) {
					nbttagcompound = chunkCache.getIfPresent(hash);
				} else {
					Log.info("Loading chunk " + hash + ": " + x + ',' + z + " while saving is in progress.");
				}
				if (nbttagcompound != null) {
					chunkCache.invalidate(hash);
				}
			} else {
				nbttagcompound = pendingchunktosave.nbtTags;
			}
		}

		if (nbttagcompound == null) {
			DataInputStream dataInputStream = regionFileCache.getChunkInputStream(x, z);

			if (dataInputStream == null) {
				return null;
			}

			try {
				nbttagcompound = CompressedStreamTools.read(dataInputStream);
			} catch (Throwable t) {
				t.printStackTrace();
				return null;
			}
		}
<commit_msg>Remove no longer relevant ThreadedChunkLoader debugging.<commit_after>package me.nallar.patched.storage;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import cpw.mods.fml.common.FMLLog;
import me.nallar.patched.annotation.FakeExtend;
import me.nallar.tickthreading.Log;
import me.nallar.tickthreading.minecraft.TickThreading;
import me.nallar.tickthreading.minecraft.storage.RegionFileCache;
import me.nallar.tickthreading.patcher.Declare;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.LongHashMap;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.MinecraftException;
import net.minecraft.world.NextTickListEntry;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.NibbleArray;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import net.minecraft.world.chunk.storage.AnvilChunkLoaderPending;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraft.world.chunk.storage.IChunkLoader;
import net.minecraft.world.storage.IThreadedFileIO;
import net.minecraft.world.storage.ThreadedFileIOBase;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.ChunkDataEvent;

@FakeExtend
public abstract class ThreadedChunkLoader extends AnvilChunkLoader implements IThreadedFileIO, IChunkLoader {
	private final java.util.LinkedHashMap<ChunkCoordIntPair, AnvilChunkLoaderPending> pendingSaves = new java.util.LinkedHashMap<ChunkCoordIntPair, AnvilChunkLoaderPending>(); // Spigot
	private final LongHashMap inProgressSaves = new LongHashMap();
	private final Object syncLockObject = new Object();
	public final File chunkSaveLocation;
	private final Cache<Long, NBTTagCompound> chunkCache;
	public final RegionFileCache regionFileCache;

	public ThreadedChunkLoader(File par1File) {
		super(par1File);
		this.chunkSaveLocation = par1File;
		chunkCache = CacheBuilder.newBuilder().maximumSize(TickThreading.instance.chunkCacheSize).build();
		regionFileCache = new RegionFileCache(chunkSaveLocation);
	}

	public boolean chunkExists(World world, int i, int j) {
		ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(i, j);

		synchronized (this.syncLockObject) {
			if (pendingSaves.containsKey(chunkcoordintpair)) {
				return true;
			}
		}

		return regionFileCache.get(i, j).isChunkSaved(i & 31, j & 31);
	}

	@Override
	public Chunk loadChunk(World world, int x, int z) {
		NBTTagCompound nbttagcompound;
		ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(x, z);

		synchronized (this.syncLockObject) {
			AnvilChunkLoaderPending pendingchunktosave = pendingSaves.get(chunkcoordintpair);

			if (pendingchunktosave == null) {
				long hash = hash(x, z);
				nbttagcompound = (NBTTagCompound) inProgressSaves.getValueByKey(hash);
				if (nbttagcompound == null) {
					nbttagcompound = chunkCache.getIfPresent(hash);
				}
				if (nbttagcompound != null) {
					chunkCache.invalidate(hash);
				}
			} else {
				nbttagcompound = pendingchunktosave.nbtTags;
			}
		}

		if (nbttagcompound == null) {
			DataInputStream dataInputStream = regionFileCache.getChunkInputStream(x, z);

			if (dataInputStream == null) {
				return null;
			}

			try {
				nbttagcompound = CompressedStreamTools.read(dataInputStream);
			} catch (Throwable t) {
				t.printStackTrace();
				return null;
			}
		}

{'fraction_non_alphanumeric': 0.09720948513035503, 'fraction_numerical': 0.0018341412288746233, 'mean_word_length': 5.524786324786325, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3521113', 'n_tokens_mistral': 2567, 'n_tokens_neox': 2422, 'n_words': 448}