<commit_before>package protocolsupport.protocol.packet.v_1_8;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.minecraft.server.v1_9_R1.EnumProtocol;
import net.minecraft.server.v1_9_R1.Packet;
import protocolsupport.protocol.packet.ServerBoundPacket;

public class PlayPacketReorderer {

	protected Packet<?> animatePacket;

	public List<Packet<?>> orderPackets(Collection<? extends Packet<?>> packets) {
		ArrayList<Packet<?>> ordered = new ArrayList<>();
		for (Packet<?> curPacket : packets) {
			int packetId = ServerBoundPacket.getId(EnumProtocol.PLAY, curPacket);
			//if the packet is use entity, we attempt to add a cached animate packet after it
			if (packetId == ServerBoundPacket.PLAY_USE_ENTITY.getId()) {
				if (animatePacket != null) {
					ordered.add(curPacket);
					ordered.add(animatePacket);
					animatePacket = null;
				} else {
					ordered.add(curPacket);
				}
			}
			//handle other packet types
			else {
				//attempt to add cached animate packet
				if (animatePacket != null) {
					ordered.add(animatePacket);
					animatePacket = null;
				}
				//if it is animate packet, we cache it
				if (packetId == ServerBoundPacket.PLAY_ANIMATION.getId()) {
					animatePacket = curPacket;
				}
				//any other type just gets added to ordered list
				else {
					ordered.add(curPacket);
				}
			}
		}
		return ordered;
	}

}<commit_msg>Use signle field to reduce memory allocation<commit_after>package protocolsupport.protocol.packet.v_1_8;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.minecraft.server.v1_9_R1.EnumProtocol;
import net.minecraft.server.v1_9_R1.Packet;
import protocolsupport.protocol.packet.ServerBoundPacket;

public class PlayPacketReorderer {

	protected Packet<?> animatePacket;

	private final ArrayList<Packet<?>> ordered = new ArrayList<>();

	public List<Packet<?>> orderPackets(Collection<? extends Packet<?>> packets) {
		ordered.clear();
		for (Packet<?> curPacket : packets) {
			int packetId = ServerBoundPacket.getId(EnumProtocol.PLAY, curPacket);
			//if the packet is use entity, we attempt to add a cached animate packet after it
			if (packetId == ServerBoundPacket.PLAY_USE_ENTITY.getId()) {
				ordered.add(curPacket);
				if (animatePacket != null) {
					ordered.add(animatePacket);
					animatePacket = null;
				}
			}
			//handle other packet types
			else {
				//attempt to add cached animate packet
				if (animatePacket != null) {
					ordered.add(animatePacket);
					animatePacket = null;
				}
				//if it is animate packet, we cache it
				if (packetId == ServerBoundPacket.PLAY_ANIMATION.getId()) {
					animatePacket = curPacket;
				}
				//any other type just gets added to ordered list
				else {
					ordered.add(curPacket);
				}
			}
		}
		return ordered;
	}

}
{'fraction_non_alphanumeric': 0.10770855332629356, 'fraction_numerical': 0.005631819781766983, 'mean_word_length': 3.674342105263158, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6987738', 'n_tokens_mistral': 1027, 'n_tokens_neox': 846, 'n_words': 225}