mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-01-08 09:27:34 +01:00
Improve WrappedDataWatcher hasIndex performance
Use the map to check for indices instead of getting the object Addresses #850
This commit is contained in:
parent
e92abda187
commit
54c252a354
@ -243,7 +243,7 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable<Wrap
|
||||
* @return True if it does, false if not
|
||||
*/
|
||||
public boolean hasIndex(int index) {
|
||||
return getObject(index) != null;
|
||||
return getMap().containsKey(index);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -388,7 +388,7 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable<Wrap
|
||||
* @param value New value
|
||||
* @param update Whether or not to inform the client
|
||||
*
|
||||
* @see {@link #setObject(WrappedDataWatcherObject, Object, boolean)}
|
||||
* @see WrappedDataWatcher#setObject(WrappedDataWatcherObject, Object, boolean)
|
||||
* @throws IllegalArgumentException in 1.9 and up if there isn't already an
|
||||
* object at this index
|
||||
*/
|
||||
@ -415,7 +415,7 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable<Wrap
|
||||
* @param value New value
|
||||
* @param update Whether or not to inform the client
|
||||
*
|
||||
* @see {@link #setObject(WrappedDataWatcherObject, Object)}
|
||||
* @see WrappedDataWatcher#setObject(WrappedDataWatcherObject, Object)
|
||||
*/
|
||||
public void setObject(int index, Serializer serializer, Object value, boolean update) {
|
||||
setObject(new WrappedDataWatcherObject(index, serializer), value, update);
|
||||
@ -435,7 +435,7 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable<Wrap
|
||||
* @param value New value
|
||||
* @param update Whether or not to inform the client
|
||||
*
|
||||
* @see {@link #setObject(int, Object, boolean)}
|
||||
* @see WrappedDataWatcher#setObject(int, Object, boolean)
|
||||
*/
|
||||
public void setObject(int index, WrappedWatchableObject value, boolean update) {
|
||||
setObject(index, value.getRawValue(), update);
|
||||
|
@ -40,7 +40,7 @@ public class WrappedDataWatcherTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void prepare() {
|
||||
BukkitInitialization.initializePackage();
|
||||
BukkitInitialization.initializeItemMeta();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -94,4 +94,14 @@ public class WrappedDataWatcherTest {
|
||||
// assertNull(Registry.get(ItemStack.class, false));
|
||||
assertNotNull(Registry.get(UUID.class, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasIndex() {
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
Serializer serializer = Registry.get(Integer.class);
|
||||
|
||||
assertFalse(watcher.hasIndex(0));
|
||||
watcher.setObject(0, serializer, 1);
|
||||
assertTrue(watcher.hasIndex(0));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user