From 83732d4ce1acfec2a236dfdf45e12d8da9058986 Mon Sep 17 00:00:00 2001 From: Ammar Askar Date: Fri, 19 Jul 2013 13:16:32 +0500 Subject: [PATCH] Simplify contains in LongHashSet along with some other minor tweaks --- .../0011-LongHash-Tweaks.patch | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/CraftBukkit-Patches/0011-LongHash-Tweaks.patch b/CraftBukkit-Patches/0011-LongHash-Tweaks.patch index d7bbe6af1..4ce7b8775 100644 --- a/CraftBukkit-Patches/0011-LongHash-Tweaks.patch +++ b/CraftBukkit-Patches/0011-LongHash-Tweaks.patch @@ -1,11 +1,23 @@ -From 395c1f65df10f279940151e1b9242861373a2578 Mon Sep 17 00:00:00 2001 +From 0db87d9664687b450e80bf526eb4f44e17bdc6a3 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 21 Jun 2013 17:13:47 +1000 Subject: [PATCH] LongHash Tweaks +diff --git a/src/main/java/org/bukkit/craftbukkit/util/LongHash.java b/src/main/java/org/bukkit/craftbukkit/util/LongHash.java +index 691cafd..9d54472 100644 +--- a/src/main/java/org/bukkit/craftbukkit/util/LongHash.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/LongHash.java +@@ -10,6 +10,6 @@ public class LongHash { + } + + public static int lsw(long l) { +- return (int) (l & 0xFFFFFFFF) + Integer.MIN_VALUE; ++ return (int) (l) + Integer.MIN_VALUE; // Spigot - remove redundant & + } + } diff --git a/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java b/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java -index 22c96c5..7c3005e 100644 +index 22c96c5..7f659b7 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java +++ b/src/main/java/org/bukkit/craftbukkit/util/LongHashSet.java @@ -31,6 +31,7 @@ public class LongHashSet { @@ -16,11 +28,15 @@ index 22c96c5..7c3005e 100644 public LongHashSet() { this(INITIAL_SIZE); -@@ -56,10 +57,22 @@ public class LongHashSet { +@@ -56,10 +57,30 @@ public class LongHashSet { } public boolean contains(int msw, int lsw) { + // Spigot start ++ if ( elements == 0 ) ++ { ++ return false; ++ } + if ( flat.contains( msw, lsw ) ) + { + return true; @@ -31,6 +47,10 @@ index 22c96c5..7c3005e 100644 public boolean contains(long value) { + // Spigot start ++ if ( elements == 0 ) ++ { ++ return false; ++ } + if ( flat.contains( value ) ) + { + return true; @@ -39,7 +59,7 @@ index 22c96c5..7c3005e 100644 int hash = hash(value); int index = (hash & 0x7FFFFFFF) % values.length; int offset = 1; -@@ -82,6 +95,7 @@ public class LongHashSet { +@@ -82,6 +103,7 @@ public class LongHashSet { } public boolean add(long value) { @@ -47,7 +67,7 @@ index 22c96c5..7c3005e 100644 int hash = hash(value); int index = (hash & 0x7FFFFFFF) % values.length; int offset = 1; -@@ -125,10 +139,18 @@ public class LongHashSet { +@@ -125,10 +147,18 @@ public class LongHashSet { } public void remove(int msw, int lsw) { @@ -67,7 +87,7 @@ index 22c96c5..7c3005e 100644 int hash = hash(value); int index = (hash & 0x7FFFFFFF) % values.length; int offset = 1; -@@ -161,6 +183,7 @@ public class LongHashSet { +@@ -161,6 +191,7 @@ public class LongHashSet { freeEntries = values.length; modCount++; @@ -76,7 +96,7 @@ index 22c96c5..7c3005e 100644 public long[] toArray() { diff --git a/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java b/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java -index 01861cc..08b543b 100644 +index 01861cc..2e5b436 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java +++ b/src/main/java/org/bukkit/craftbukkit/util/LongObjectHashMap.java @@ -28,6 +28,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { @@ -87,11 +107,15 @@ index 01861cc..08b543b 100644 public LongObjectHashMap() { initialize(); -@@ -61,6 +62,13 @@ public class LongObjectHashMap implements Cloneable, Serializable { +@@ -61,6 +62,17 @@ public class LongObjectHashMap implements Cloneable, Serializable { } public V get(long key) { + // Spigot start ++ if ( size == 0 ) ++ { ++ return null; ++ } + V val = flat.get( key ); + if ( val != null ) + { @@ -101,7 +125,7 @@ index 01861cc..08b543b 100644 int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1)); long[] inner = keys[index]; if (inner == null) return null; -@@ -78,6 +86,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { +@@ -78,6 +90,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { } public V put(long key, V value) { @@ -109,7 +133,7 @@ index 01861cc..08b543b 100644 int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1)); long[] innerKeys = keys[index]; V[] innerValues = values[index]; -@@ -124,6 +133,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { +@@ -124,6 +137,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { } public V remove(long key) { @@ -117,7 +141,7 @@ index 01861cc..08b543b 100644 int index = (int) (keyIndex(key) & (BUCKET_SIZE - 1)); long[] inner = keys[index]; if (inner == null) { -@@ -174,6 +184,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { +@@ -174,6 +188,7 @@ public class LongObjectHashMap implements Cloneable, Serializable { size = 0; Arrays.fill(keys, null); Arrays.fill(values, null); @@ -196,5 +220,5 @@ index 0000000..9416f6e + } +} -- -1.8.1.2 +1.8.1.msysgit.1