<commit_before>package me.nallar.tickprofiler.minecraft.profiling;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import com.google.common.base.Functions;
import com.google.common.collect.Ordering;

import cpw.mods.fml.common.FMLLog;
import me.nallar.tickprofiler.minecraft.commands.ProfileCommand;
import me.nallar.tickprofiler.minecraft.entitylist.EntityList;
import me.nallar.tickprofiler.util.MappingUtil;
import me.nallar.tickprofiler.util.TableFormatter;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ReportedException;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.common.ForgeDummyContainer;
import org.cliffc.high_scale_lib.NonBlockingHashMap;

public class EntityTickProfiler {
	private int ticks;
	private final AtomicLong totalTime = new AtomicLong();
	private int chunkX;
	private int chunkZ;

	public void setLocation(final int x, final int z) {
		chunkX = x;
		chunkZ = z;
	}

	public void runEntities(World world, ArrayList<Entity> toTick) {
		long end = System.nanoTime();
		long start;
		boolean isGlobal = EntityList.profilingState == ProfileCommand.ProfilingState.GLOBAL;
		for (int i = 0; i < toTick.size(); i++) {
			Entity entity = toTick.get(i);

			start = end;
			if (entity.ridingEntity != null) {
				if (!entity.ridingEntity.isDead && entity.ridingEntity.riddenByEntity == entity) {
					continue;
				}

				entity.ridingEntity.riddenByEntity = null;
				entity.ridingEntity = null;
			}

			if (!entity.isDead) {
				try {
					world.updateEntity(entity);
				} catch (Throwable var8) {
					CrashReport crashReport = CrashReport.makeCrashReport(var8, "Ticking entity");
					CrashReportCategory crashReportCategory = crashReport.makeCategory("Entity being ticked");
					entity.func_85029_a(crashReportCategory);

					if (ForgeDummyContainer.removeErroringEntities) {
						FMLLog.severe(crashReport.getCompleteReport());
						world.removeEntity(entity);
					} else {
						throw new ReportedException(crashReport);
					}
				}
			}

			if (entity.isDead) {
				int chunkX = entity.chunkCoordX;
				int chunkZ = entity.chunkCoordZ;

				if (entity.addedToChunk && world.getChunkProvider().chunkExists(chunkX, chunkZ)) {
					world.getChunkFromChunkCoords(chunkX, chunkZ).removeEntity(entity);
				}

				toTick.remove(i--);
				world.releaseEntitySkin(entity);
			}
			end = System.nanoTime();

			if (isGlobal || (entity.chunkCoordX == chunkX && entity.chunkCoordZ == chunkZ)) {
				record(entity, end - start);
			}
		}
	}

	public void runTileEntities(World world, ArrayList<TileEntity> toTick) {
		IChunkProvider chunkProvider = world.getChunkProvider();
		Iterator<TileEntity> iterator = toTick.iterator();
		long end = System.nanoTime();<commit_msg>Check that entity is at correct position in entity list before removal.<commit_after>package me.nallar.tickprofiler.minecraft.profiling;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import com.google.common.base.Functions;
import com.google.common.collect.Ordering;

import cpw.mods.fml.common.FMLLog;
import me.nallar.tickprofiler.minecraft.commands.ProfileCommand;
import me.nallar.tickprofiler.minecraft.entitylist.EntityList;
import me.nallar.tickprofiler.util.MappingUtil;
import me.nallar.tickprofiler.util.TableFormatter;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ReportedException;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.common.ForgeDummyContainer;
import org.cliffc.high_scale_lib.NonBlockingHashMap;

public class EntityTickProfiler {
	private int ticks;
	private final AtomicLong totalTime = new AtomicLong();
	private int chunkX;
	private int chunkZ;

	public void setLocation(final int x, final int z) {
		chunkX = x;
		chunkZ = z;
	}

	public void runEntities(World world, ArrayList<Entity> toTick) {
		long end = System.nanoTime();
		long start;
		boolean isGlobal = EntityList.profilingState == ProfileCommand.ProfilingState.GLOBAL;
		for (int i = 0; i < toTick.size(); i++) {
			Entity entity = toTick.get(i);

			start = end;
			if (entity.ridingEntity != null) {
				if (!entity.ridingEntity.isDead && entity.ridingEntity.riddenByEntity == entity) {
					continue;
				}

				entity.ridingEntity.riddenByEntity = null;
				entity.ridingEntity = null;
			}

			if (!entity.isDead) {
				try {
					world.updateEntity(entity);
				} catch (Throwable var8) {
					CrashReport crashReport = CrashReport.makeCrashReport(var8, "Ticking entity");
					CrashReportCategory crashReportCategory = crashReport.makeCategory("Entity being ticked");
					entity.func_85029_a(crashReportCategory);

					if (ForgeDummyContainer.removeErroringEntities) {
						FMLLog.severe(crashReport.getCompleteReport());
						world.removeEntity(entity);
					} else {
						throw new ReportedException(crashReport);
					}
				}
			}

			if (entity.isDead) {
				int chunkX = entity.chunkCoordX;
				int chunkZ = entity.chunkCoordZ;

				if (entity.addedToChunk && world.getChunkProvider().chunkExists(chunkX, chunkZ)) {
					world.getChunkFromChunkCoords(chunkX, chunkZ).removeEntity(entity);
				}

				if (toTick.size() <= i || toTick.get(i) != entity) {
					toTick.remove(entity);
				} else {
					toTick.remove(i--);
				}
				world.releaseEntitySkin(entity);
			}
			end = System.nanoTime();

			if (isGlobal || (entity.chunkCoordX == chunkX && entity.chunkCoordZ == chunkZ)) {
				record(entity, end - start);
			}
		}
	}

	public void runTileEntities(World world, ArrayList<TileEntity> toTick) {
		IChunkProvider chunkProvider = world.getChunkProvider();
		Iterator<TileEntity> iterator = toTick.iterator();
		long end = System.nanoTime();
{'fraction_non_alphanumeric': 0.11135405278775574, 'fraction_numerical': 0.002498828674059035, 'mean_word_length': 4.4363327674023765, 'pattern_counts': {'":': 0, '<': 12, '<?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': '261613', 'n_tokens_mistral': 2304, 'n_tokens_neox': 2041, 'n_words': 391}