Try and improve performance of the registry by avoiding superType.cast.

This commit is contained in:
cpw 2015-03-14 15:32:34 -04:00
parent c7c29979c9
commit 278612ad98
1 changed files with 14 additions and 4 deletions

View File

@ -128,7 +128,7 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
public void putObject(Object objName, Object obj) public void putObject(Object objName, Object obj)
{ {
String name = (String) objName; String name = (String) objName;
I thing = superType.cast(obj); I thing = cast(obj);
if (name == null) throw new NullPointerException("Can't use a null-name for the registry."); if (name == null) throw new NullPointerException("Can't use a null-name for the registry.");
if (name.isEmpty()) throw new IllegalArgumentException("Can't use an empty name for the registry."); if (name.isEmpty()) throw new IllegalArgumentException("Can't use an empty name for the registry.");
@ -224,9 +224,19 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
*/ */
public I getRaw(int id) public I getRaw(int id)
{ {
return superType.cast(super.getObjectById(id)); return cast(super.getObjectById(id));
} }
/**
* superType.cast appears to be expensive. Skip it for speed?
* @param obj
* @return
*/
@SuppressWarnings("unchecked")
private I cast(Object obj)
{
return (I)(obj);
}
/** /**
* Get the object identified by the specified name. * Get the object identified by the specified name.
* *
@ -235,7 +245,7 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
*/ */
public I getRaw(String name) public I getRaw(String name)
{ {
I ret = superType.cast(super.getObject(name)); I ret = cast(super.getObject(name));
if (ret == null) // no match, try aliases recursively if (ret == null) // no match, try aliases recursively
{ {
@ -461,7 +471,7 @@ public class FMLControlledNamespacedRegistry<I> extends RegistryNamespaced {
FMLLog.severe("The substitution of %s has already occured. You cannot duplicate substitutions", nameToReplace); FMLLog.severe("The substitution of %s has already occured. You cannot duplicate substitutions", nameToReplace);
throw new ExistingSubstitutionException(nameToReplace, toReplace); throw new ExistingSubstitutionException(nameToReplace, toReplace);
} }
I replacement = superType.cast(toReplace); I replacement = cast(toReplace);
I original = getRaw(nameToReplace); I original = getRaw(nameToReplace);
if (original == null) if (original == null)
{ {