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

remove redundant boxing and casting #51

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/src/processing/awt/PSurfaceAWT.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ public void setIcon(PImage image) {
Class<?> thinkDifferent =
Thread.currentThread().getContextClassLoader().loadClass(td);
Method method =
thinkDifferent.getMethod("setIconImage", new Class[] { java.awt.Image.class });
method.invoke(null, new Object[] { awtImage });
thinkDifferent.getMethod("setIconImage", Image.class);
method.invoke(null, awtImage);
} catch (Exception e) {
e.printStackTrace(); // That's unfortunate
}
Expand Down Expand Up @@ -655,8 +655,8 @@ protected void setProcessingIcon(Frame frame) {
Class<?> thinkDifferent =
Thread.currentThread().getContextClassLoader().loadClass(td);
Method method =
thinkDifferent.getMethod("setIconImage", new Class[] { java.awt.Image.class });
method.invoke(null, new Object[] { Toolkit.getDefaultToolkit().getImage(url) });
thinkDifferent.getMethod("setIconImage", Image.class);
method.invoke(null, Toolkit.getDefaultToolkit().getImage(url));
} catch (Exception e) {
e.printStackTrace(); // That's unfortunate
}
Expand Down
31 changes: 10 additions & 21 deletions core/src/processing/core/PApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1581,18 +1581,7 @@ public void unregisterMethod(String name, Object target) {
}
}


protected void handleMethods(String methodName) {
synchronized (registerLock) {
RegisteredMethods meth = registerMap.get(methodName);
if (meth != null) {
meth.handle();
}
}
}


protected void handleMethods(String methodName, Object[] args) {
protected void handleMethods(String methodName, Object...args) {
synchronized (registerLock) {
RegisteredMethods meth = registerMap.get(methodName);
if (meth != null) {
Expand Down Expand Up @@ -2223,7 +2212,7 @@ protected PGraphics makeGraphics(int w, int h,
Class<?> rendererClass =
Thread.currentThread().getContextClassLoader().loadClass(renderer);

Constructor<?> constructor = rendererClass.getConstructor(new Class[] { });
Constructor<?> constructor = rendererClass.getConstructor();
PGraphics pg = (PGraphics) constructor.newInstance();

pg.setParent(this);
Expand Down Expand Up @@ -2707,7 +2696,7 @@ protected void handleMouseEvent(MouseEvent event) {
break;
}

handleMethods("mouseEvent", new Object[] { event });
handleMethods("mouseEvent", event);

switch (action) {
case MouseEvent.PRESS:
Expand Down Expand Up @@ -2979,7 +2968,7 @@ protected void handleKeyEvent(KeyEvent event) {
}
*/

handleMethods("keyEvent", new Object[] { event });
handleMethods("keyEvent", event);

// if someone else wants to intercept the key, they should
// set key to zero (or something besides the ESC).
Expand Down Expand Up @@ -3824,8 +3813,8 @@ public void dispose() {
*/
public void method(String name) {
try {
Method method = getClass().getMethod(name, new Class[] {});
method.invoke(this, new Object[] { });
Method method = getClass().getMethod(name);
method.invoke(this);

} catch (IllegalArgumentException e) {
e.printStackTrace();
Expand Down Expand Up @@ -6676,8 +6665,8 @@ static private void selectCallback(File selectedFile,
try {
Class<?> callbackClass = callbackObject.getClass();
Method selectMethod =
callbackClass.getMethod(callbackMethod, new Class[] { File.class });
selectMethod.invoke(callbackObject, new Object[] { selectedFile });
callbackClass.getMethod(callbackMethod, File.class);
selectMethod.invoke(callbackObject, selectedFile);

} catch (IllegalAccessException iae) {
System.err.println(callbackMethod + "() must be public");
Expand Down Expand Up @@ -10802,8 +10791,8 @@ public void uncaughtException(Thread t, Throwable e) {
Class<?> thinkDifferent =
Thread.currentThread().getContextClassLoader().loadClass(td);
Method method =
thinkDifferent.getMethod("init", new Class[] { PApplet.class });
method.invoke(null, new Object[] { sketch });
thinkDifferent.getMethod("init", PApplet.class);
method.invoke(null, sketch);
} catch (Exception e) {
e.printStackTrace(); // That's unfortunate
}
Expand Down
32 changes: 14 additions & 18 deletions core/src/processing/data/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ public void parseInto(Object enclosingObject, String fieldName) {
con = target.getDeclaredConstructor(); //new Class[] { });
// PApplet.println("no enclosing class");
} else {
con = target.getDeclaredConstructor(new Class[] { enclosingClass });
con = target.getDeclaredConstructor(enclosingClass);
// PApplet.println("enclosed by " + enclosingClass.getName());
}
if (!con.canAccess(null)) {
Expand Down Expand Up @@ -1509,17 +1509,15 @@ protected void saveODS(OutputStream os) throws IOException {
entry = new ZipEntry("content.xml");
zos.putNextEntry(entry);
//lines = new String[] {
writeUTF(zos, new String[] {
xmlHeader,
"<office:document-content" +
" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"" +
" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"" +
" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"" +
" office:version=\"1.2\">",
" <office:body>",
" <office:spreadsheet>",
" <table:table table:name=\"Sheet1\" table:print=\"false\">"
});
writeUTF(zos, xmlHeader,
"<office:document-content" +
" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"" +
" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\"" +
" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\"" +
" office:version=\"1.2\">",
" <office:body>",
" <office:spreadsheet>",
" <table:table table:name=\"Sheet1\" table:print=\"false\">");
//zos.write(PApplet.join(lines, "\n").getBytes());

byte[] rowStart = " <table:table-row>\n".getBytes();
Expand All @@ -1546,12 +1544,10 @@ protected void saveODS(OutputStream os) throws IOException {
}

//lines = new String[] {
writeUTF(zos, new String[] {
" </table:table>",
" </office:spreadsheet>",
" </office:body>",
"</office:document-content>"
});
writeUTF(zos, " </table:table>",
" </office:spreadsheet>",
" </office:body>",
"</office:document-content>");
//zos.write(PApplet.join(lines, "\n").getBytes());
zos.closeEntry();

Expand Down
6 changes: 3 additions & 3 deletions core/src/processing/opengl/PGraphicsOpenGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ public class PGraphicsOpenGL extends PGraphics {
// Using the technique alternative to finalization described in:
// http://www.oracle.com/technetwork/articles/java/finalization-137655.html
private static ReferenceQueue<Object> refQueue = new ReferenceQueue<>();
private static List<Disposable<? extends Object>> reachableWeakReferences =
private static List<Disposable<?>> reachableWeakReferences =
new LinkedList<>();

static final private int MAX_DRAIN_GLRES_ITERATIONS = 10;

static void drainRefQueueBounded() {
int iterations = 0;
while (iterations < MAX_DRAIN_GLRES_ITERATIONS) {
Disposable<? extends Object> res =
(Disposable<? extends Object>) refQueue.poll();
Disposable<?> res =
(Disposable<?>) refQueue.poll();
if (res == null) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/processing/opengl/PJOGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ public int createShader(int type) {

@Override
public void shaderSource(int shader, String source) {
gl2.glShaderSource(shader, 1, new String[] { source }, (int[]) null, 0);
gl2.glShaderSource(shader, 1, new String[] { source }, null, 0);
Copy link
Owner

Choose a reason for hiding this comment

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

Have you tested this? This would have been written the original way due to a compiler error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was able to compile without issue, and in all of my tests, the results were the same 👍

Feels kinda like it shouldn't be allowed, but while the individual elements of a primitive array aren't nullable, arrays are. So null is a perfectly legal value here.

}

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/src/processing/opengl/PShapeOpenGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -4681,7 +4681,7 @@ public void draw(PGraphics g) {
if (family == GROUP) {
if (fragmentedGroup(gl)) {
for (int i = 0; i < childCount; i++) {
((PShapeOpenGL) children[i]).draw(gl);
children[i].draw(gl);
}
} else {
PImage tex = null;
Expand Down
4 changes: 2 additions & 2 deletions core/src/processing/opengl/Texture.java
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ protected boolean bufferUpdate() {
protected void getSourceMethods() {
try {
disposeBufferMethod = bufferSource.getClass().
getMethod("disposeBuffer", new Class[] { Object.class });
getMethod("disposeBuffer", Object.class);
} catch (Exception e) {
throw new RuntimeException("Provided source object doesn't have a " +
"disposeBuffer method.");
Expand Down Expand Up @@ -1659,7 +1659,7 @@ protected class BufferData {
void dispose() {
try {
// Disposing the native buffer.
disposeBufferMethod.invoke(bufferSource, new Object[] { natBuf });
disposeBufferMethod.invoke(bufferSource, natBuf);
natBuf = null;
rgbBuf = null;
} catch (Exception e) {
Expand Down