From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: lukas81298 Date: Sun, 13 Dec 2020 13:42:55 +0100 Subject: [PATCH] do not create unnecessary copies of passenger list diff --git a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMount.java b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMount.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMount.java +++ b/src/main/java/net/minecraft/network/protocol/game/PacketPlayOutMount.java @@ -0,0 +0,0 @@ public class PacketPlayOutMount implements Packet { public PacketPlayOutMount(Entity entity) { this.a = entity.getId(); - List list = entity.getPassengers(); + List list = entity.passengers; // Paper - do not create a copy of the list this.b = new int[list.size()]; diff --git a/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java +++ b/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java @@ -0,0 +0,0 @@ public class EntityTrackerEntry { public final void tick() { this.a(); } // Paper - OBFHELPER public void a() { - List list = this.tracker.getPassengers(); + List list = this.tracker.passengers; // Paper - do not copy list if (!list.equals(this.p)) { - this.p = list; + this.p = com.google.common.collect.ImmutableList.copyOf(list); // Paper - only copy list if something has changed this.broadcastIncludingSelf(new PacketPlayOutMount(this.tracker)); // CraftBukkit } @@ -0,0 +0,0 @@ public class EntityTrackerEntry { } } - if (!this.tracker.getPassengers().isEmpty()) { + if (!this.tracker.passengers.isEmpty()) { // Paper - do not create copy of list consumer.accept(new PacketPlayOutMount(this.tracker)); } diff --git a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java +++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java @@ -0,0 +0,0 @@ Sections go from 0..16. Now whenever a section is not empty, it can potentially list.add(entity); } - if (!entity.getPassengers().isEmpty()) { + if (!entity.passengers.isEmpty()) { // Paper - do not copy list list1.add(entity); } } diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne } protected boolean q(Entity entity) { - return this.getPassengers().size() < 1; + return this.passengers.size() < 1; // Paper - do not copy list } public final float getCollisionBorderSize() { return bg(); } // Paper - OBFHELPER @@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne } public boolean isVehicle() { - return !this.getPassengers().isEmpty(); + return !this.passengers.isEmpty(); // Paper - do not copy list } public boolean bt() { @@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne } public boolean w(Entity entity) { - Iterator iterator = this.getPassengers().iterator(); + Iterator iterator = this.passengers.iterator(); // Paper - do not copy list Entity entity1; @@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne } public boolean a(Class oclass) { - Iterator iterator = this.getPassengers().iterator(); + Iterator iterator = this.passengers.iterator(); // Paper - do not copy list Entity entity; @@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne public Collection getAllPassengers() { Set set = Sets.newHashSet(); - Iterator iterator = this.getPassengers().iterator(); + Iterator iterator = this.passengers.iterator(); // Paper - do not copy list while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); @@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne private void a(boolean flag, Set set) { Entity entity; - for (Iterator iterator = this.getPassengers().iterator(); iterator.hasNext(); entity.a(flag, set)) { + for (Iterator iterator = this.passengers.iterator(); iterator.hasNext(); entity.a(flag, set)) { // Paper - do not copy list entity = (Entity) iterator.next(); if (!flag || EntityPlayer.class.isAssignableFrom(entity.getClass())) { set.add(entity); diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java +++ b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalTame.java @@ -0,0 +0,0 @@ public class PathfinderGoalTame extends PathfinderGoal { @Override public void e() { if (!this.entity.isTamed() && this.entity.getRandom().nextInt(50) == 0) { - Entity entity = (Entity) this.entity.getPassengers().get(0); + Entity entity = this.entity.passengers.isEmpty() ? null : this.entity.passengers.get(0); // Paper - do not copy list, fixed array out of bounds exception as well if (entity == null) { return; diff --git a/src/main/java/net/minecraft/world/entity/animal/EntityPig.java b/src/main/java/net/minecraft/world/entity/animal/EntityPig.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/animal/EntityPig.java +++ b/src/main/java/net/minecraft/world/entity/animal/EntityPig.java @@ -0,0 +0,0 @@ public class EntityPig extends EntityAnimal implements ISteerable, ISaddleable { @Nullable @Override public Entity getRidingPassenger() { - return this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0); + return this.passengers.isEmpty() ? null : (Entity) this.passengers.get(0); // Paper - do not copy list } @Override diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java b/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java +++ b/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java @@ -0,0 +0,0 @@ public abstract class EntityHorseAbstract extends EntityAnimal implements IInven @Nullable @Override public Entity getRidingPassenger() { - return this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0); + return this.passengers.isEmpty() ? null : (Entity) this.passengers.get(0); // Paper - do not copy list } @Nullable diff --git a/src/main/java/net/minecraft/world/entity/monster/EntityRavager.java b/src/main/java/net/minecraft/world/entity/monster/EntityRavager.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/monster/EntityRavager.java +++ b/src/main/java/net/minecraft/world/entity/monster/EntityRavager.java @@ -0,0 +0,0 @@ public class EntityRavager extends EntityRaider { @Nullable @Override public Entity getRidingPassenger() { - return this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0); + return this.passengers.isEmpty() ? null : (Entity) this.passengers.get(0); // Paper - do not copy list } @Override diff --git a/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java b/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java +++ b/src/main/java/net/minecraft/world/entity/vehicle/EntityBoat.java @@ -0,0 +0,0 @@ public class EntityBoat extends Entity { super.tick(); this.r(); if (this.cs()) { - if (this.getPassengers().isEmpty() || !(this.getPassengers().get(0) instanceof EntityHuman)) { + if (this.passengers.isEmpty() || !(this.passengers.get(0) instanceof EntityHuman)) { // Paper - do not copy list this.a(false, false); } @@ -0,0 +0,0 @@ public class EntityBoat extends Entity { Entity entity = (Entity) list.get(j); if (!entity.w(this)) { - if (flag && this.getPassengers().size() < 2 && !entity.isPassenger() && entity.getWidth() < this.getWidth() && entity instanceof EntityLiving && !(entity instanceof EntityWaterAnimal) && !(entity instanceof EntityHuman)) { + if (flag && this.passengers.size() < 2 && !entity.isPassenger() && entity.getWidth() < this.getWidth() && entity instanceof EntityLiving && !(entity instanceof EntityWaterAnimal) && !(entity instanceof EntityHuman)) { // Paper - do not copy passenger list entity.startRiding(this); } else { this.collide(entity); @@ -0,0 +0,0 @@ public class EntityBoat extends Entity { float f = 0.0F; float f1 = (float) ((this.dead ? 0.009999999776482582D : this.bc()) + entity.bb()); - if (this.getPassengers().size() > 1) { - int i = this.getPassengers().indexOf(entity); + if (this.passengers.size() > 1) { // Paper - do not copy list + int i = this.passengers.indexOf(entity); // Paper - do not copy list if (i == 0) { f = 0.2F; @@ -0,0 +0,0 @@ public class EntityBoat extends Entity { entity.yaw += this.ak; entity.setHeadRotation(entity.getHeadRotation() + this.ak); this.a(entity); - if (entity instanceof EntityAnimal && this.getPassengers().size() > 1) { + if (entity instanceof EntityAnimal && this.passengers.size() > 1) { // Paper - do not copy list int j = entity.getId() % 2 == 0 ? 90 : 270; entity.n(((EntityAnimal) entity).aA + (float) j); @@ -0,0 +0,0 @@ public class EntityBoat extends Entity { @Override protected boolean q(Entity entity) { - return this.getPassengers().size() < 2 && !this.a((Tag) TagsFluid.WATER); + return this.passengers.size() < 2 && !this.a((Tag) TagsFluid.WATER); // Paper - do not copy list } @Nullable @Override public Entity getRidingPassenger() { - List list = this.getPassengers(); + List list = this.passengers; // Paper - do not copy list return list.isEmpty() ? null : (Entity) list.get(0); } diff --git a/src/main/java/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java b/src/main/java/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java +++ b/src/main/java/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java @@ -0,0 +0,0 @@ public abstract class EntityMinecartAbstract extends Entity { vec3d1 = new Vec3D(d8 * d4 / d6, vec3d1.y, d8 * d5 / d6); this.setMot(vec3d1); - Entity entity = this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0); + Entity entity = this.passengers.isEmpty() ? null : (Entity) this.passengers.get(0); // Paper - do not copy list if (entity instanceof EntityHuman) { Vec3D vec3d2 = entity.getMot();