Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements #2220

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public Joystick[] loadJoysticks(InputManager inputManager) {
if (!disableSensors) {
joystickList.add(sensorJoyInput.loadJoystick(joystickList.size(), inputManager));
}
return joystickList.toArray( new Joystick[joystickList.size()] );
stephengold marked this conversation as resolved.
Show resolved Hide resolved
return joystickList.toArray(new Joystick[0]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Joystick[] loadJoysticks(InputManager inputManager) {
// load physical gamepads/joysticks
joystickList.addAll(joystickJoyInput.loadJoysticks(joystickList.size(), inputManager));
// return the list of joysticks back to InputManager
return joystickList.toArray( new Joystick[joystickList.size()] );
return joystickList.toArray(new Joystick[0]);
}

public boolean onGenericMotion(MotionEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,8 @@ public void onSensorChanged(SensorEvent se) {
return;
}
synchronized(sensorData.valuesLock) {
for (int i=0; i<sensorData.lastValues.length; i++) {
sensorData.lastValues[i] = se.values[i];
}
if (sensorData.lastValues.length >= 0)
System.arraycopy(se.values, 0, sensorData.lastValues, 0, sensorData.lastValues.length);
}

if (sensorData.axes.size() > 0) {
Expand Down
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/anim/Armature.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Armature(Joint[] jointList) {
rootJointList.add(joint);
}
}
rootJoints = rootJointList.toArray(new Joint[rootJointList.size()]);
rootJoints = rootJointList.toArray(new Joint[0]);

createSkinningMatrices();

Expand Down
8 changes: 2 additions & 6 deletions jme3-core/src/main/java/com/jme3/anim/tween/Tweens.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,13 +597,9 @@ public CallTweenMethod(double length, Object target, String methodName, Object..
// So now set up the real args list.
this.args = new Object[args.length + 1];
if (tIndex == 0) {
for (int i = 0; i < args.length; i++) {
this.args[i + 1] = args[i];
}
System.arraycopy(args, 0, this.args, 1, args.length);
} else {
for (int i = 0; i < args.length; i++) {
this.args[i] = args[i];
}
System.arraycopy(args, 0, this.args, 0, args.length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void visit(Spatial spatial) {
padJointTracks(tracks, staticJoints[i]);
}

clip.setTracks(tracks.toArray(new TransformTrack[tracks.size()]));
clip.setTracks(tracks.toArray(new TransformTrack[0]));

composer.addAnimClip(clip);
}
Expand Down
5 changes: 2 additions & 3 deletions jme3-core/src/main/java/com/jme3/animation/Animation.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.jme3.util.clone.JmeCloneable;

import java.io.IOException;
import java.util.Collections;

/**
* The animation class updates the animation target with the tracks of a given type.
Expand Down Expand Up @@ -139,9 +140,7 @@ void setTime(float time, float blendAmount, AnimControl control, AnimChannel cha
* @param tracksArray The tracks to set.
*/
public void setTracks(Track[] tracksArray) {
for (Track track : tracksArray) {
tracks.add(track);
}
Collections.addAll(tracks, tracksArray);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/animation/Skeleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Skeleton(Bone[] boneList) {
rootBoneList.add(b);
}
}
rootBones = rootBoneList.toArray(new Bone[rootBoneList.size()]);
rootBones = rootBoneList.toArray(new Bone[0]);

createSkinningMatrices();

Expand Down
3 changes: 1 addition & 2 deletions jme3-core/src/main/java/com/jme3/app/DetailedProfiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ public void vpStep(VpStep step, ViewPort vp, RenderQueue.Bucket bucket) {
curVpPath = vpPath.toString();
} else {
if (bucket != null) {
path.append(curAppPath).append("/").append(curVpPath).append("/")
.append(bucket.name() + " Bucket");
path.append(curAppPath).append("/").append(curVpPath).append("/").append(bucket.name()).append(" Bucket");
} else {
path.append(curAppPath).append("/").append(vpPath);
curVpPath = vpPath.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -326,11 +327,8 @@ public void setProfiler(AppProfiler profiler) {
* @throws IOException if an I/O error occurs
*/
protected void writeImageFile(File file) throws IOException {
OutputStream outStream = new FileOutputStream(file);
try {
try(OutputStream outStream = Files.newOutputStream(file.toPath())) {
JmeSystem.writeImageFile(outStream, "png", outBuf, width, height);
} finally {
outStream.close();
}
}
}
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/cinematic/Cinematic.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void onPause() {
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(cinematicEvents.toArray(new CinematicEvent[cinematicEvents.size()]), "cinematicEvents", null);
oc.write(cinematicEvents.toArray(new CinematicEvent[0]), "cinematicEvents", null);
oc.writeStringSavableMap(cameras, "cameras", null);
oc.write(timeLine, "timeLine", null);

Expand Down
3 changes: 1 addition & 2 deletions jme3-core/src/main/java/com/jme3/cinematic/TimeLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public int getLastKeyFrameIndex() {
@SuppressWarnings("unchecked")
public void write(JmeExporter ex) throws IOException {
OutputCapsule oc = ex.getCapsule(this);
ArrayList list = new ArrayList();
list.addAll(values());
ArrayList list = new ArrayList(values());
oc.writeSavableArrayList(list, "keyFrames", null);
}

Expand Down
5 changes: 1 addition & 4 deletions jme3-core/src/main/java/com/jme3/light/LightList.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,7 @@ public void write(JmeExporter ex) throws IOException {
OutputCapsule oc = ex.getCapsule(this);
// oc.write(owner, "owner", null);

ArrayList<Light> lights = new ArrayList<>();
for (int i = 0; i < listSize; i++) {
lights.add(list[i]);
}
ArrayList<Light> lights = new ArrayList<>(Arrays.asList(list).subList(0, listSize));
oc.writeSavableArrayList(lights, "lights", null);
}

Expand Down
11 changes: 3 additions & 8 deletions jme3-core/src/main/java/com/jme3/math/Spline.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.jme3.export.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -84,10 +85,7 @@ public Spline(SplineType splineType, Vector3f[] controlPoints, float curveTensio
if (splineType == SplineType.Nurb) {
throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!");
}
for (int i = 0; i < controlPoints.length; i++) {
Vector3f vector3f = controlPoints[i];
this.controlPoints.add(vector3f);
}
Collections.addAll(this.controlPoints, controlPoints);
type = splineType;
this.curveTension = curveTension;
this.cycle = cycle;
Expand Down Expand Up @@ -164,10 +162,7 @@ private void initCatmullRomWayPoints(List<Vector3f> list) {
CRcontrolPoints.add(list.get(0).subtract(list.get(1).subtract(list.get(0))));
}

for (Iterator<Vector3f> it = list.iterator(); it.hasNext();) {
Vector3f vector3f = it.next();
CRcontrolPoints.add(vector3f);
}
CRcontrolPoints.addAll(list);
if (cycle) {
CRcontrolPoints.add(list.get(1));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public List<? extends Device> chooseDevices(List<? extends Platform> platforms)
//still no one found, try without interop
LOG.warning("No device with OpenCL-OpenGL-interop found, try without");
for (Platform p : platforms) {
for (Device d : p.getDevices()) {
result.add(d);
}
result.addAll(p.getDevices());
if (!result.isEmpty()) {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ assert isValidNumber(fb) : "Invalid Matrix4f value " + uniform.getValue() + " fo
case FloatArray:
fb = uniform.getMultiData();
assert isValidNumber(fb) : "Invalid float array value "
+ Arrays.asList((float[]) uniform.getValue()) + " for " + uniform.getBinding();
+ Arrays.toString((float[]) uniform.getValue()) + " for " + uniform.getBinding();
gl.glUniform1(loc, fb);
break;
case Vector2Array:
Expand Down
3 changes: 1 addition & 2 deletions jme3-core/src/main/java/com/jme3/scene/Mesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,7 @@ public void setStreamed() {
*/
@Deprecated
public void setInterleaved() {
ArrayList<VertexBuffer> vbs = new ArrayList<>();
vbs.addAll(buffersList);
ArrayList<VertexBuffer> vbs = new ArrayList<>(buffersList);

// ArrayList<VertexBuffer> vbs = new ArrayList<VertexBuffer>(buffers.values());
// index buffer not included when interleaving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private void updateAllInstanceData() {
if (globalInstanceData != null) {
allData.addAll(Arrays.asList(globalInstanceData));
}
allInstanceData = allData.toArray(new VertexBuffer[allData.size()]);
allInstanceData = allData.toArray(new VertexBuffer[0]);
}

@Override
Expand Down
7 changes: 2 additions & 5 deletions jme3-core/src/main/java/com/jme3/scene/shape/Surface.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
import com.jme3.util.BufferUtils;
import java.io.IOException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
stephengold marked this conversation as resolved.
Show resolved Hide resolved

/**
* This class represents a surface described by knots, weights and control points.
Expand Down Expand Up @@ -229,7 +226,7 @@ private void buildSurface(boolean smooth) {
}
}

Vector3f[] verticesArray = vertices.toArray(new Vector3f[vertices.size()]);
Vector3f[] verticesArray = vertices.toArray(new Vector3f[0]);
// normalMap merges normals of faces that will be rendered smooth
Map<Vector3f, Vector3f> normalMap = new HashMap<>(verticesArray.length);
for (int i = 0; i < indices.length; i += 3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ protected boolean isVarying(ShaderGenerationInfo info, ShaderNodeVariable v) {
for (ShaderNodeVariable shaderNodeVariable : info.getVaryings()) {
if (shaderNodeVariable.equals(v)) {
isVarying = true;
break;
}
}
return isVarying;
Expand Down
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/util/JmeFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class JmeFormatter extends Formatter {
final private StringBuffer store = new StringBuffer();

public JmeFormatter(){
lineSeparator = System.getProperty("line.separator");
lineSeparator = System.lineSeparator();
format = new MessageFormat("{0,time}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ public TriangleData(Vector3f tangent, Vector3f binormal, Vector3f normal) {
}

public void setIndex(int[] index) {
for (int i = 0; i < index.length; i++) {
this.index[i] = index[i];
}
System.arraycopy(index, 0, this.index, 0, index.length);
}
}

Expand Down
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/util/xml/SAXUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static float parseFloat(String f) throws SAXException {
}

public static boolean parseBool(String bool, boolean def) throws SAXException {
if (bool == null || bool.equals(""))
if (bool == null || bool.isEmpty())
return def;
else
return Boolean.valueOf(bool);
Expand Down
stephengold marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ private int findPrevMatch(BinaryIdContentPair oldPair,
protected byte[] fixClassAlias(byte[] bytes, int width) {
if (bytes.length != width) {
byte[] newAlias = new byte[width];
for (int x = width - bytes.length; x < width; x++)
newAlias[x] = bytes[x - bytes.length];
if (width - (width - bytes.length) >= 0)
System.arraycopy(bytes, width - bytes.length - bytes.length, newAlias, width - bytes.length, width - (width - bytes.length));
return newAlias;
}
return bytes;
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'0 + offset' should be replaced by 'offset'.

Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,7 @@ protected String readString(InputStream f, int length) throws IOException {

protected String readString(int length, int offset) throws IOException {
byte[] data = new byte[length];
for(int j = 0; j < length; j++) {
data[j] = dataArray[j+offset];
}
System.arraycopy(dataArray, 0 + offset, data, 0, length);

return new String(data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -562,9 +559,7 @@ private ArrayList<Savable> savableArrayListFromArray(Savable[] savables) {
return null;
}
ArrayList<Savable> arrayList = new ArrayList<>(savables.length);
for (int x = 0; x < savables.length; x++) {
arrayList.add(savables[x]);
}
Collections.addAll(arrayList, savables);
return arrayList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,7 @@ else if (possibleMagic == DEFAULT_OBJECT)

byte[] rVal = new byte[1 + size];
rVal[0] = (byte) size;
for (int x = 1; x < rVal.length; x++)
rVal[x] = bytes[bytes.length - size - 1 + x];
System.arraycopy(bytes, bytes.length - size - 1 + 1, rVal, 1, rVal.length - 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete - 1 + 1 please.


return rVal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,8 @@ public static byte[] readData(byte[] store, int bytes, InputStream is) throws IO
public static byte[] rightAlignBytes(byte[] bytes, int width) {
if (bytes.length != width) {
byte[] rVal = new byte[width];
for (int x = width - bytes.length; x < width; x++) {
rVal[x] = bytes[x - (width - bytes.length)];
}
if (width - (width - bytes.length) >= 0)
System.arraycopy(bytes, width - bytes.length - (width - bytes.length), rVal, width - bytes.length, width - (width - bytes.length));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please simplify width - bytes.length - (width - bytes.length) to 0 and width - (width - bytes.length) to bytes.length.

return rVal;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ private void loadFromRoot(List<Statement> roots) throws IOException{

String[] split = materialName.split(":", 2);

if (materialName.equals("")){
if (materialName.isEmpty()){
throw new MatParseException("Material name cannot be empty", materialStat);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ protected void readShaderNodeDefinition(List<Statement> statements, ShaderNodeDe
shaderNodeDefinition.getShadersPath().add(shaderName);
} else if (line.startsWith("Documentation")) {
if (isLoadDoc) {
String doc = "";
StringBuilder doc = new StringBuilder();
for (Statement statement1 : statement.getContents()) {
doc += "\n" + statement1.getLine();
doc.append("\n").append(statement1.getLine());
}
shaderNodeDefinition.setDocumentation(doc);
shaderNodeDefinition.setDocumentation(doc.toString());
}
} else if (line.startsWith("Input")) {
varNames.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ protected void readFace(){
}else if (split.length == 2){
v = Integer.parseInt(split[0].trim());
vt = Integer.parseInt(split[1].trim());
}else if (split.length == 3 && !split[1].equals("")){
}else if (split.length == 3 && !split[1].isEmpty()){
v = Integer.parseInt(split[0].trim());
vt = Integer.parseInt(split[1].trim());
vn = Integer.parseInt(split[2].trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public Image load(InputStream in, boolean flipY) throws IOException{
while (true){
String ln = readString(in);
ln = ln.trim();
if (ln.startsWith("#") || ln.equals("")){
if (ln.startsWith("#") || ln.isEmpty()){
if (ln.equals("#?RADIANCE") || ln.equals("#?RGBE"))
verifiedFormat = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ private boolean checkFileIdentifier(byte[] b) {
for (int i = 0; i < 12; i++) {
if (b[i] != fileIdentifier[i]) {
check = false;
break;
}
}
return check;
Expand Down
Loading
Loading