2014-01-22 08:19:39 +00:00
|
|
|
From 97a4d307554c92c124c5c29167ff5cd83cbb385a Mon Sep 17 00:00:00 2001
|
2013-12-13 00:45:53 +00:00
|
|
|
From: md_5 <git@md-5.net>
|
|
|
|
Date: Fri, 13 Dec 2013 11:45:47 +1100
|
|
|
|
Subject: [PATCH] Optimize DataWatcher
|
|
|
|
|
|
|
|
Use primitive orientated collections, as well as more effective copies across collections.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/DataWatcher.java b/src/main/java/net/minecraft/server/DataWatcher.java
|
2013-12-14 08:50:33 +00:00
|
|
|
index 90a2a80..cca6bd9 100644
|
2013-12-13 00:45:53 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/DataWatcher.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/DataWatcher.java
|
2013-12-14 08:48:13 +00:00
|
|
|
@@ -14,8 +14,13 @@ public class DataWatcher {
|
2013-12-13 00:45:53 +00:00
|
|
|
|
|
|
|
private final Entity a;
|
|
|
|
private boolean b = true;
|
|
|
|
- private static final HashMap c = new HashMap();
|
|
|
|
- private final Map d = new HashMap();
|
2013-12-14 08:48:13 +00:00
|
|
|
+ // Spigot Start
|
|
|
|
+ private static final gnu.trove.map.TObjectIntMap classToId = new gnu.trove.map.hash.TObjectIntHashMap( 10, 0.5f, -1 );
|
|
|
|
+ private final gnu.trove.map.TIntObjectMap dataValues = new gnu.trove.map.hash.TIntObjectHashMap( 10, 0.5f, -1 );
|
|
|
|
+ // These exist as an attempt at backwards compatability for (broken) NMS plugins
|
|
|
|
+ private static final Map c = gnu.trove.TDecorators.wrap( classToId );
|
|
|
|
+ private final Map d = gnu.trove.TDecorators.wrap( dataValues );
|
|
|
|
+ // Spigot End
|
2013-12-13 00:45:53 +00:00
|
|
|
private boolean e;
|
|
|
|
private ReadWriteLock f = new ReentrantReadWriteLock();
|
|
|
|
|
2013-12-14 08:48:13 +00:00
|
|
|
@@ -24,19 +29,19 @@ public class DataWatcher {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(int i, Object object) {
|
|
|
|
- Integer integer = (Integer) c.get(object.getClass());
|
2013-12-14 08:50:33 +00:00
|
|
|
+ int integer = classToId.get(object.getClass()); // Spigot
|
2013-12-14 08:48:13 +00:00
|
|
|
|
2013-12-14 08:50:33 +00:00
|
|
|
- if (integer == null) {
|
|
|
|
+ if (integer == -1) { // Spigot
|
2013-12-14 08:48:13 +00:00
|
|
|
throw new IllegalArgumentException("Unknown data type: " + object.getClass());
|
|
|
|
} else if (i > 31) {
|
|
|
|
throw new IllegalArgumentException("Data value id is too big with " + i + "! (Max is " + 31 + ")");
|
|
|
|
- } else if (this.d.containsKey(Integer.valueOf(i))) {
|
|
|
|
+ } else if (this.dataValues.containsKey(i)) { // Spigot
|
|
|
|
throw new IllegalArgumentException("Duplicate id value for " + i + "!");
|
|
|
|
} else {
|
2013-12-14 08:50:33 +00:00
|
|
|
- WatchableObject watchableobject = new WatchableObject(integer.intValue(), i, object);
|
|
|
|
+ WatchableObject watchableobject = new WatchableObject(integer, i, object); // Spigot
|
2013-12-13 00:45:53 +00:00
|
|
|
|
|
|
|
this.f.writeLock().lock();
|
|
|
|
- this.d.put(Integer.valueOf(i), watchableobject);
|
2013-12-14 08:48:13 +00:00
|
|
|
+ this.dataValues.put(i, watchableobject); // Spigot
|
2013-12-13 00:45:53 +00:00
|
|
|
this.f.writeLock().unlock();
|
|
|
|
this.b = false;
|
|
|
|
}
|
2013-12-14 08:48:13 +00:00
|
|
|
@@ -46,7 +51,7 @@ public class DataWatcher {
|
2013-12-13 00:45:53 +00:00
|
|
|
WatchableObject watchableobject = new WatchableObject(j, i, null);
|
|
|
|
|
|
|
|
this.f.writeLock().lock();
|
|
|
|
- this.d.put(Integer.valueOf(i), watchableobject);
|
2013-12-14 08:48:13 +00:00
|
|
|
+ this.dataValues.put(i, watchableobject); // Spigot
|
2013-12-13 00:45:53 +00:00
|
|
|
this.f.writeLock().unlock();
|
|
|
|
this.b = false;
|
|
|
|
}
|
2013-12-14 08:48:13 +00:00
|
|
|
@@ -81,7 +86,7 @@ public class DataWatcher {
|
2013-12-13 00:45:53 +00:00
|
|
|
WatchableObject watchableobject;
|
|
|
|
|
|
|
|
try {
|
|
|
|
- watchableobject = (WatchableObject) this.d.get(Integer.valueOf(i));
|
2013-12-14 08:48:13 +00:00
|
|
|
+ watchableobject = (WatchableObject) this.dataValues.get(i); // Spigot
|
2013-12-13 00:45:53 +00:00
|
|
|
} catch (Throwable throwable) {
|
|
|
|
CrashReport crashreport = CrashReport.a(throwable, "Getting synched entity data");
|
|
|
|
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Synched entity data");
|
2013-12-14 08:48:13 +00:00
|
|
|
@@ -133,7 +138,7 @@ public class DataWatcher {
|
2013-12-13 00:45:53 +00:00
|
|
|
|
|
|
|
if (this.e) {
|
|
|
|
this.f.readLock().lock();
|
|
|
|
- Iterator iterator = this.d.values().iterator();
|
2013-12-14 08:48:13 +00:00
|
|
|
+ Iterator iterator = this.dataValues.valueCollection().iterator(); // Spigot
|
2013-12-13 00:45:53 +00:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
WatchableObject watchableobject = (WatchableObject) iterator.next();
|
2013-12-14 08:48:13 +00:00
|
|
|
@@ -157,7 +162,7 @@ public class DataWatcher {
|
2013-12-13 00:45:53 +00:00
|
|
|
|
|
|
|
public void a(PacketDataSerializer packetdataserializer) {
|
|
|
|
this.f.readLock().lock();
|
|
|
|
- Iterator iterator = this.d.values().iterator();
|
2013-12-14 08:48:13 +00:00
|
|
|
+ Iterator iterator = this.dataValues.valueCollection().iterator(); // Spigot
|
2013-12-13 00:45:53 +00:00
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
WatchableObject watchableobject = (WatchableObject) iterator.next();
|
2013-12-14 08:48:13 +00:00
|
|
|
@@ -170,18 +175,11 @@ public class DataWatcher {
|
2013-12-13 00:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public List c() {
|
|
|
|
- ArrayList arraylist = null;
|
|
|
|
+ ArrayList arraylist = new ArrayList(); // Spigot
|
|
|
|
|
|
|
|
this.f.readLock().lock();
|
|
|
|
|
|
|
|
- WatchableObject watchableobject;
|
|
|
|
-
|
|
|
|
- for (Iterator iterator = this.d.values().iterator(); iterator.hasNext(); arraylist.add(watchableobject)) {
|
|
|
|
- watchableobject = (WatchableObject) iterator.next();
|
|
|
|
- if (arraylist == null) {
|
|
|
|
- arraylist = new ArrayList();
|
|
|
|
- }
|
|
|
|
- }
|
2013-12-14 08:48:13 +00:00
|
|
|
+ arraylist.addAll(this.dataValues.valueCollection()); // Spigot
|
2013-12-13 00:45:53 +00:00
|
|
|
|
|
|
|
this.f.readLock().unlock();
|
|
|
|
return arraylist;
|
2013-12-14 08:48:13 +00:00
|
|
|
@@ -295,12 +293,14 @@ public class DataWatcher {
|
2013-12-13 00:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
|
|
|
- c.put(Byte.class, Integer.valueOf(0));
|
|
|
|
- c.put(Short.class, Integer.valueOf(1));
|
|
|
|
- c.put(Integer.class, Integer.valueOf(2));
|
|
|
|
- c.put(Float.class, Integer.valueOf(3));
|
|
|
|
- c.put(String.class, Integer.valueOf(4));
|
|
|
|
- c.put(ItemStack.class, Integer.valueOf(5));
|
|
|
|
- c.put(ChunkCoordinates.class, Integer.valueOf(6));
|
|
|
|
+ // Spigot Start - remove valueOf
|
2013-12-14 08:48:13 +00:00
|
|
|
+ classToId.put(Byte.class, 0);
|
|
|
|
+ classToId.put(Short.class, 1);
|
|
|
|
+ classToId.put(Integer.class, 2);
|
|
|
|
+ classToId.put(Float.class, 3);
|
|
|
|
+ classToId.put(String.class, 4);
|
|
|
|
+ classToId.put(ItemStack.class, 5);
|
|
|
|
+ classToId.put(ChunkCoordinates.class, 6);
|
2013-12-13 00:45:53 +00:00
|
|
|
+ // Spigot End
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--
|
|
|
|
1.8.3.2
|
|
|
|
|