mirror of
https://github.com/Eaglercraft-Archive/Eaglercraftx-1.8.8-src.git
synced 2025-06-27 18:38:14 -05:00
Update #40 - FPS boost and fixed IndexOutOfBoundsException
This commit is contained in:
@ -22,6 +22,8 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* {@code StopWatch} provides a convenient API for timings.
|
||||
@ -314,7 +316,7 @@ public class StopWatch {
|
||||
} else if (this.runningState == State.UNSTARTED) {
|
||||
return 0;
|
||||
} else if (this.runningState == State.RUNNING) {
|
||||
return System.nanoTime() - this.startTimeNanos;
|
||||
return EagRuntime.nanoTime() - this.startTimeNanos;
|
||||
}
|
||||
throw new IllegalStateException("Illegal running state has occurred.");
|
||||
}
|
||||
@ -497,7 +499,7 @@ public class StopWatch {
|
||||
if (this.runningState != State.SUSPENDED) {
|
||||
throw new IllegalStateException("Stopwatch must be suspended to resume. ");
|
||||
}
|
||||
this.startTimeNanos += System.nanoTime() - this.stopTimeNanos;
|
||||
this.startTimeNanos += EagRuntime.nanoTime() - this.stopTimeNanos;
|
||||
this.runningState = State.RUNNING;
|
||||
}
|
||||
|
||||
@ -518,7 +520,7 @@ public class StopWatch {
|
||||
if (this.runningState != State.RUNNING) {
|
||||
throw new IllegalStateException("Stopwatch is not running. ");
|
||||
}
|
||||
this.stopTimeNanos = System.nanoTime();
|
||||
this.stopTimeNanos = EagRuntime.nanoTime();
|
||||
this.splitState = SplitState.SPLIT;
|
||||
}
|
||||
|
||||
@ -540,7 +542,7 @@ public class StopWatch {
|
||||
if (this.runningState != State.UNSTARTED) {
|
||||
throw new IllegalStateException("Stopwatch already started. ");
|
||||
}
|
||||
this.startTimeNanos = System.nanoTime();
|
||||
this.startTimeNanos = EagRuntime.nanoTime();
|
||||
this.startTimeMillis = System.currentTimeMillis();
|
||||
this.runningState = State.RUNNING;
|
||||
}
|
||||
@ -561,7 +563,7 @@ public class StopWatch {
|
||||
throw new IllegalStateException("Stopwatch is not running. ");
|
||||
}
|
||||
if (this.runningState == State.RUNNING) {
|
||||
this.stopTimeNanos = System.nanoTime();
|
||||
this.stopTimeNanos = EagRuntime.nanoTime();
|
||||
this.stopTimeMillis = System.currentTimeMillis();
|
||||
}
|
||||
this.runningState = State.STOPPED;
|
||||
@ -583,7 +585,7 @@ public class StopWatch {
|
||||
if (this.runningState != State.RUNNING) {
|
||||
throw new IllegalStateException("Stopwatch must be running to suspend. ");
|
||||
}
|
||||
this.stopTimeNanos = System.nanoTime();
|
||||
this.stopTimeNanos = EagRuntime.nanoTime();
|
||||
this.stopTimeMillis = System.currentTimeMillis();
|
||||
this.runningState = State.SUSPENDED;
|
||||
}
|
||||
|
@ -4,22 +4,17 @@ package org.json;
|
||||
Public Domain.
|
||||
*/
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -378,15 +373,15 @@ public class JSONObject {
|
||||
* @throws JSONException
|
||||
* If a getter returned a non-finite number.
|
||||
*/
|
||||
public JSONObject(Object bean) {
|
||||
this();
|
||||
this.populateMap(bean);
|
||||
}
|
||||
|
||||
private JSONObject(Object bean, Set<Object> objectsRecord) {
|
||||
this();
|
||||
this.populateMap(bean, objectsRecord);
|
||||
}
|
||||
// public JSONObject(Object bean) {
|
||||
// this();
|
||||
// this.populateMap(bean);
|
||||
// }
|
||||
//
|
||||
// private JSONObject(Object bean, Set<Object> objectsRecord) {
|
||||
// this();
|
||||
// this.populateMap(bean, objectsRecord);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Construct a JSONObject from an Object, using reflection to find the
|
||||
@ -1725,104 +1720,104 @@ public class JSONObject {
|
||||
* @throws JSONException
|
||||
* If a getter returned a non-finite number.
|
||||
*/
|
||||
private void populateMap(Object bean) {
|
||||
populateMap(bean, Collections.newSetFromMap(new IdentityHashMap<Object, Boolean>()));
|
||||
}
|
||||
// private void populateMap(Object bean) {
|
||||
// populateMap(bean, Collections.newSetFromMap(new IdentityHashMap<Object, Boolean>()));
|
||||
// }
|
||||
|
||||
private void populateMap(Object bean, Set<Object> objectsRecord) {
|
||||
Class<?> klass = bean.getClass();
|
||||
|
||||
// If klass is a System class then set includeSuperClass to false.
|
||||
|
||||
boolean includeSuperClass = klass.getClassLoader() != null;
|
||||
|
||||
Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
|
||||
for (final Method method : methods) {
|
||||
final int modifiers = method.getModifiers();
|
||||
if (Modifier.isPublic(modifiers)
|
||||
&& !Modifier.isStatic(modifiers)
|
||||
&& method.getParameterTypes().length == 0
|
||||
&& !method.isBridge()
|
||||
&& method.getReturnType() != Void.TYPE
|
||||
&& isValidMethodName(method.getName())) {
|
||||
final String key = getKeyNameFromMethod(method);
|
||||
if (key != null && !key.isEmpty()) {
|
||||
try {
|
||||
final Object result = method.invoke(bean);
|
||||
if (result != null) {
|
||||
// check cyclic dependency and throw error if needed
|
||||
// the wrap and populateMap combination method is
|
||||
// itself DFS recursive
|
||||
if (objectsRecord.contains(result)) {
|
||||
throw recursivelyDefinedObjectException(key);
|
||||
}
|
||||
|
||||
objectsRecord.add(result);
|
||||
|
||||
testValidity(result);
|
||||
this.map.put(key, wrap(result, objectsRecord));
|
||||
|
||||
objectsRecord.remove(result);
|
||||
|
||||
// we don't use the result anywhere outside of wrap
|
||||
// if it's a resource we should be sure to close it
|
||||
// after calling toString
|
||||
if (result instanceof Closeable) {
|
||||
try {
|
||||
((Closeable) result).close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException ignore) {
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
} catch (InvocationTargetException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValidMethodName(String name) {
|
||||
return !"getClass".equals(name) && !"getDeclaringClass".equals(name);
|
||||
}
|
||||
|
||||
private static String getKeyNameFromMethod(Method method) {
|
||||
final int ignoreDepth = getAnnotationDepth(method, JSONPropertyIgnore.class);
|
||||
if (ignoreDepth > 0) {
|
||||
final int forcedNameDepth = getAnnotationDepth(method, JSONPropertyName.class);
|
||||
if (forcedNameDepth < 0 || ignoreDepth <= forcedNameDepth) {
|
||||
// the hierarchy asked to ignore, and the nearest name override
|
||||
// was higher or non-existent
|
||||
return null;
|
||||
}
|
||||
}
|
||||
JSONPropertyName annotation = getAnnotation(method, JSONPropertyName.class);
|
||||
if (annotation != null && annotation.value() != null && !annotation.value().isEmpty()) {
|
||||
return annotation.value();
|
||||
}
|
||||
String key;
|
||||
final String name = method.getName();
|
||||
if (name.startsWith("get") && name.length() > 3) {
|
||||
key = name.substring(3);
|
||||
} else if (name.startsWith("is") && name.length() > 2) {
|
||||
key = name.substring(2);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
// if the first letter in the key is not uppercase, then skip.
|
||||
// This is to maintain backwards compatibility before PR406
|
||||
// (https://github.com/stleary/JSON-java/pull/406/)
|
||||
if (key.length() == 0 || Character.isLowerCase(key.charAt(0))) {
|
||||
return null;
|
||||
}
|
||||
if (key.length() == 1) {
|
||||
key = key.toLowerCase(Locale.ROOT);
|
||||
} else if (!Character.isUpperCase(key.charAt(1))) {
|
||||
key = key.substring(0, 1).toLowerCase(Locale.ROOT) + key.substring(1);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
// private void populateMap(Object bean, Set<Object> objectsRecord) {
|
||||
// Class<?> klass = bean.getClass();
|
||||
//
|
||||
// // If klass is a System class then set includeSuperClass to false.
|
||||
//
|
||||
// boolean includeSuperClass = klass.getClassLoader() != null;
|
||||
//
|
||||
// Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
|
||||
// for (final Method method : methods) {
|
||||
// final int modifiers = method.getModifiers();
|
||||
// if (Modifier.isPublic(modifiers)
|
||||
// && !Modifier.isStatic(modifiers)
|
||||
// && method.getParameterTypes().length == 0
|
||||
// && !method.isBridge()
|
||||
// && method.getReturnType() != Void.TYPE
|
||||
// && isValidMethodName(method.getName())) {
|
||||
// final String key = getKeyNameFromMethod(method);
|
||||
// if (key != null && !key.isEmpty()) {
|
||||
// try {
|
||||
// final Object result = method.invoke(bean);
|
||||
// if (result != null) {
|
||||
// // check cyclic dependency and throw error if needed
|
||||
// // the wrap and populateMap combination method is
|
||||
// // itself DFS recursive
|
||||
// if (objectsRecord.contains(result)) {
|
||||
// throw recursivelyDefinedObjectException(key);
|
||||
// }
|
||||
//
|
||||
// objectsRecord.add(result);
|
||||
//
|
||||
// testValidity(result);
|
||||
// this.map.put(key, wrap(result, objectsRecord));
|
||||
//
|
||||
// objectsRecord.remove(result);
|
||||
//
|
||||
// // we don't use the result anywhere outside of wrap
|
||||
// // if it's a resource we should be sure to close it
|
||||
// // after calling toString
|
||||
// if (result instanceof Closeable) {
|
||||
// try {
|
||||
// ((Closeable) result).close();
|
||||
// } catch (IOException ignore) {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (IllegalAccessException ignore) {
|
||||
// } catch (IllegalArgumentException ignore) {
|
||||
// } catch (InvocationTargetException ignore) {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static boolean isValidMethodName(String name) {
|
||||
// return !"getClass".equals(name) && !"getDeclaringClass".equals(name);
|
||||
// }
|
||||
//
|
||||
// private static String getKeyNameFromMethod(Method method) {
|
||||
// final int ignoreDepth = getAnnotationDepth(method, JSONPropertyIgnore.class);
|
||||
// if (ignoreDepth > 0) {
|
||||
// final int forcedNameDepth = getAnnotationDepth(method, JSONPropertyName.class);
|
||||
// if (forcedNameDepth < 0 || ignoreDepth <= forcedNameDepth) {
|
||||
// // the hierarchy asked to ignore, and the nearest name override
|
||||
// // was higher or non-existent
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// JSONPropertyName annotation = getAnnotation(method, JSONPropertyName.class);
|
||||
// if (annotation != null && annotation.value() != null && !annotation.value().isEmpty()) {
|
||||
// return annotation.value();
|
||||
// }
|
||||
// String key;
|
||||
// final String name = method.getName();
|
||||
// if (name.startsWith("get") && name.length() > 3) {
|
||||
// key = name.substring(3);
|
||||
// } else if (name.startsWith("is") && name.length() > 2) {
|
||||
// key = name.substring(2);
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
// // if the first letter in the key is not uppercase, then skip.
|
||||
// // This is to maintain backwards compatibility before PR406
|
||||
// // (https://github.com/stleary/JSON-java/pull/406/)
|
||||
// if (key.length() == 0 || Character.isLowerCase(key.charAt(0))) {
|
||||
// return null;
|
||||
// }
|
||||
// if (key.length() == 1) {
|
||||
// key = key.toLowerCase(Locale.ROOT);
|
||||
// } else if (!Character.isUpperCase(key.charAt(1))) {
|
||||
// key = key.substring(0, 1).toLowerCase(Locale.ROOT) + key.substring(1);
|
||||
// }
|
||||
// return key;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Searches the class hierarchy to see if the method or it's super
|
||||
@ -2734,10 +2729,11 @@ public class JSONObject {
|
||||
|| object.getClass().getClassLoader() == null) {
|
||||
return object.toString();
|
||||
}
|
||||
if (objectsRecord != null) {
|
||||
return new JSONObject(object, objectsRecord);
|
||||
}
|
||||
return new JSONObject(object);
|
||||
// if (objectsRecord != null) {
|
||||
// return new JSONObject(object, objectsRecord);
|
||||
// }
|
||||
// return new JSONObject(object);
|
||||
throw new UnsupportedOperationException("Unsupported type: " + object.getClass().getSimpleName());
|
||||
}
|
||||
catch (JSONException exception) {
|
||||
throw exception;
|
||||
|
Reference in New Issue
Block a user