summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Adams <dinnerbone@dinnerbone.com>2012-01-14 14:56:47 +0000
committerNathan Adams <dinnerbone@dinnerbone.com>2012-01-14 15:01:44 +0000
commit52c526f313f1f701cbe042612db572da0edcc600 (patch)
tree904d91f89635cd6d643870905bd8f339248e34e9
parent77a12d4dceb9401449bf4a851acf2ee44559ee1b (diff)
downloadcraftbukkit-52c526f313f1f701cbe042612db572da0edcc600.tar
craftbukkit-52c526f313f1f701cbe042612db572da0edcc600.tar.gz
craftbukkit-52c526f313f1f701cbe042612db572da0edcc600.tar.lz
craftbukkit-52c526f313f1f701cbe042612db572da0edcc600.tar.xz
craftbukkit-52c526f313f1f701cbe042612db572da0edcc600.zip
Small optimization in EntityPlayer by caching the hashcode. Thanks to a very old PR by Belphemur. In addition, changed and slightly improved the hashcode formula for entities
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java33
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java6
2 files changed, 17 insertions, 22 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 8727cd14..1674846c 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -206,24 +206,6 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return !entity.isAlive();
}
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final CraftEntity other = (CraftEntity) obj;
- if (this.server != other.server && (this.server == null || !this.server.equals(other.server))) {
- return false;
- }
- if (this.entity != other.entity && (this.entity == null || !this.entity.equals(other.entity))) {
- return false;
- }
- return true;
- }
-
public Server getServer() {
return server;
}
@@ -320,10 +302,21 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
@Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final CraftEntity other = (CraftEntity) obj;
+ return (this.getEntityId() == other.getEntityId());
+ }
+
+ @Override
public int hashCode() {
int hash = 7;
- hash = 89 * hash + (this.server != null ? this.server.hashCode() : 0);
- hash = 89 * hash + (this.entity != null ? this.entity.hashCode() : 0);
+ hash = 29 * hash + this.getEntityId();
return hash;
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 1b965f0d..8d99a64c 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -54,6 +54,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
private long lastPlayed = 0;
private boolean hasPlayedBefore = false;
private Set<String> channels = new HashSet<String>();
+ private int hash = 0;
public CraftPlayer(CraftServer server, EntityPlayer entity) {
super(server, entity);
@@ -583,8 +584,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public int hashCode() {
- int hash = 5;
- hash = 97 * hash + (this.getName() != null ? this.getName().hashCode() : 0);
+ if (hash == 0 || hash == 485) {
+ hash = 97 * 5 + (this.getName() != null ? this.getName().hashCode() : 0);
+ }
return hash;
}