Skip to content

Commit

Permalink
Cleanup the use of Float primitive wrapper. As of Java 9, the VM can …
Browse files Browse the repository at this point in the history
…do a better job of handling the (#3890)

coversion from a float primitive to a Float Object or vice versa.

This is an extension of the work done in #2498.

No tests have been touched as those expressly need to manage the conversion.
  • Loading branch information
BradWalker authored Apr 3, 2022
1 parent f47ca71 commit 190ffcb
Show file tree
Hide file tree
Showing 21 changed files with 30 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ public Object read(String className, Properties properties) {
} else if (classNames[5].equals(className)) {
return new Long(properties.getLong(propertyName, 0l));
} else if (classNames[6].equals(className)) {
return new Float(properties.getFloat(propertyName, 0f));
return properties.getFloat(propertyName, 0f);
} else if (classNames[7].equals(className)) {
return new Double(properties.getDouble(propertyName, 0d));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public Float getNumberValue(CharSequence image) {
Float f = super.getNumberValue(image);
if(f == null) {
if(image.length() > 0 && image.charAt(0) == '0') {
f = new Float(0);
f = 0F;
}
}
return f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public static Object validate(Object valueObj, DBColumn col) throws DBException

case Types.FLOAT:
case Types.REAL:
return valueObj instanceof Float ? valueObj : new Float(valueObj.toString());
return valueObj instanceof Float ? valueObj : Float.valueOf(valueObj.toString());

case Types.DECIMAL:
case Types.NUMERIC:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public static Object defaultScalarValue(int type) {
case Common.TYPE_LONG:
return new Long(0);
case Common.TYPE_FLOAT:
return new Float(0.0);
return 0.0F;
case Common.TYPE_DOUBLE:
return new Double(0.0);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ public Object defaultScalarValue(int type) {
case Common.TYPE_LONG:
return new Long(0);
case Common.TYPE_FLOAT:
return new Float(0.0);
return 0.0F;
case Common.TYPE_DOUBLE:
return new Double(0.0);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class CPFloatInfo extends CPEntry {

CPFloatInfo(ConstantPool pool, float v) {
super(pool);
value = new Float(v);
value = v;
}

public final int getTag() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void addSample( String className, String methodName, Object argument, flo
Map methods = getSubMap( classes, className );
Map args = getSubMap( methods, methodName );
List samples = getSubList( args, argument2String(argument) );
samples.add( new Float( value ) );
samples.add(value);
}

public void flush() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
*/

package org.netbeans.performance.impl.logparsing;

import org.netbeans.performance.spi.html.*;
import org.netbeans.performance.spi.*;
import java.util.*;

/**Wrapper class for a JDK garbage collection log. This wrapper parses the log
* and comes up with statistics representing data from it. It does not hold onto
* all of the GC events in a garbage collection log. For a log wrapper that can
Expand Down Expand Up @@ -139,21 +141,21 @@ protected void parse() throws ParseException {
}
}

addElement (new NameValueLogElement (GC_SECONDS, new Float(totalGcTime)));
addElement (new NameValueLogElement (GC_SECONDS, totalGcTime));
addElement (new NameValueLogElement (GC_TOTAL, new Integer(gcs.size())));
addElement (new NameValueLogElement (GC_FULLTOTAL, new Integer(fullGcCount)));
addElement (new NameValueLogElement (GC_MINORTOTAL, new Integer(gcs.size() - fullGcCount)));
addElement (new NameValueLogElement (GC_TOTALGARBAGE, new Long(totalCollected)));
addElement (new NameValueLogElement (GC_HGES, new Integer(heapChangeCount)));
addElement (new NameValueLogElement (GC_AVGCOLLECTEDPERGC, new Long(totalCollected / gcs.size())));
addElement (new NameValueLogElement (GC_SECSMAJOR, new Float(totalMajorGcTime)));
addElement (new NameValueLogElement (GC_SECSMINOR, new Float(totalMinorGcTime)));
addElement (new NameValueLogElement (GC_SECSMAJOR, totalMajorGcTime));
addElement (new NameValueLogElement (GC_SECSMINOR, totalMinorGcTime));
if (fullGcCount != 0) {
addElement (new NameValueLogElement (GC_AVGMILLISMAJOR, new Float((totalMajorGcTime / fullGcCount) * 1000)));
addElement (new NameValueLogElement (GC_AVGMILLISMAJOR, (float)((totalMajorGcTime / fullGcCount) * 1000)));
} else {
addElement (new NameValueLogElement (GC_AVGMILLISMAJOR, new Float (0)));
addElement (new NameValueLogElement (GC_AVGMILLISMAJOR, 0F));
}
addElement (new NameValueLogElement (GC_AVGMILLISMINOR, new Float((totalMinorGcTime / (gcs.size() - fullGcCount))*1000)));
addElement (new NameValueLogElement (GC_AVGMILLISMINOR, (float)((totalMinorGcTime / (gcs.size() - fullGcCount))*1000)));

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ protected void averageElements (ValueLogElement[] el) {
* used to create this element.
* the set of values used to create this element. */
public Float getMin() {
return new Float (samples[0]);
return samples[0];
}

/** Returns the highest value in the set of values
* used to create this element.
* the set of values used to create this element. */
public Float getMax() {
return new Float(samples[samples.length-1]);
return samples[samples.length-1];
}

/** Returns the mean, or arithmetic average of
Expand All @@ -105,7 +105,7 @@ public Float getMedian() {
} else {
result = samples[samples.length/2];
}
return new Float(result);
return result;
}

/** Returns the values used to create this element. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ private ArrayWrapper readNewArray() throws IOException {
} else if (aw.classdesc.name.equals("[J")) { // NOI18N
aw.values.add(new Long(readLong()));
} else if (aw.classdesc.name.equals("[F")) { // NOI18N
aw.values.add(new Float(Float.intBitsToFloat(readInt())));
aw.values.add(Float.intBitsToFloat(readInt()));
} else if (aw.classdesc.name.equals("[D")) { // NOI18N
aw.values.add(new Double(Double.longBitsToDouble(readLong())));
} else if (aw.classdesc.name.equals("[C")) { // NOI18N
Expand Down Expand Up @@ -566,7 +566,7 @@ private List<NameValue> readNoWrClass(ClassDesc cd) throws IOException {
} else if (fd.type.equals("J")) { // NOI18N
values.add(new NameValue(fd, new Long(readLong())));
} else if (fd.type.equals("F")) { // NOI18N
values.add(new NameValue(fd, new Float(Float.intBitsToFloat(readInt()))));
values.add(new NameValue(fd, Float.intBitsToFloat(readInt())));
} else if (fd.type.equals("D")) { // NOI18N
values.add(new NameValue(fd, new Double(Double.longBitsToDouble(readLong()))));
} else if (fd.type.equals("C")) { // NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,6 @@ public class TestFrame extends javax.swing.JFrame {
public TestFrame() {
setDefaultCloseOperation (javax.swing.WindowConstants.EXIT_ON_CLOSE);
initComponents();
/*
try {
System.setProperty("os.version", new Float(3.5).toString());
Method m = Toolkit.class.getDeclaredMethod("setDesktopProperty",
new Class[] {String.class, Object.class});
m.setAccessible(true);
m.invoke(java.awt.Toolkit.getDefaultToolkit(),
new Object[] {"win.xpstyle.themeActive", Boolean.FALSE });
UIManager.setLookAndFeel(new PseudoWin());
// UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
} catch (Exception e) {
e.printStackTrace();
}
*/

try {
// UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private Object defaultValue() {
}

if (getConvertedType().equals(Float.class)) {
value = new Float(0f);
value = 0f;
}

if (getConvertedType().equals(Long.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ private Object getObject(Object[] params) throws Exception {
case 3:
return new Long(value);
case 4:
return new Float(value);
return Float.valueOf(value);
case 5:
return new Double(value);
case 6:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public float getLineAscentCorrection() {
*/
public void setLineAscentCorrection(float correction) {
PrintPreferences.setLineAscentCorrection(correction);
firePropertyChange(PROP_LINE_ASCENT_CORRECTION, null, new Float(correction));
firePropertyChange(PROP_LINE_ASCENT_CORRECTION, null, correction);
}

public void writeExternal(ObjectOutput obtos) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,31 +409,6 @@ public String getColumnToolTipText(int col) {
return columnToolTips[col];
}

// private Float getNodeTimeRel(PrestimeCPUCCTNode pNode) {
// return new Float(pNode.getTotalTime0InPerCent());
// }
//
// private String getNodeTime(PrestimeCPUCCTNode pNode) {
// return StringUtils.mcsTimeToString(pNode.getTotalTime0()) + " ms (" // NOI18N
// + percentFormat.format(pNode.getTotalTime0InPerCent() / 100) + ")"; // NOI18N
// }
//
// private String getNodeWaitTime(PrestimeCPUCCTNode pNode) {
// return StringUtils.mcsTimeToString(pNode.getWaitTime0()) + " ms"; // NOI18N
// }
//
// private String getNodeSleepTime(PrestimeCPUCCTNode pNode) {
// return StringUtils.mcsTimeToString(pNode.getSleepTime0()) + " ms"; // NOI18N
// }
//
// private String getNodeSecondaryTime(PrestimeCPUCCTNode pNode) {
// return StringUtils.mcsTimeToString(pNode.getTotalTime1()) + " ms"; // NOI18N
// }
//
// private Integer getNodeInvocations(PrestimeCPUCCTNode pNode) {
// return Integer.valueOf(pNode.getNCalls());
// }

private Integer getNodeMethodId(PrestimeCPUCCTNode pNode) {
return Integer.valueOf(pNode.getMethodId());
}
Expand Down Expand Up @@ -630,7 +605,7 @@ public void valueChanged(ListSelectionEvent e) {
}

protected Float getNodeTimeRel(long time, float percent) {
return new Float(percent);
return percent;
}

protected String getNodeTime(long time, float percent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected boolean supportsSubtreeCallGraph() {


protected Float getNodeTimeRel(long time, float percent) {
return new Float(time);
return (float)time;
}

protected String getNodeTime(long time, float percent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected Object computeValueAt(int row, int col) {
case 0:
return flatProfileContainer.getMethodNameAtRow(row);
case 1:
return new Float(flatProfileContainer.getTimeInMcs0AtRow(row));
return (float)flatProfileContainer.getTimeInMcs0AtRow(row);
case 2:
value = flatProfileContainer.getTimeInMcs0AtRow(row);
return (value > 0 ? "+" : "") + StringUtils.mcsTimeToString(value) + " ms"; // NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ protected Object computeValueAt(int row, int col) {
case 0:
return flatProfileContainer.getMethodNameAtRow(row);
case 1:
return new Float(flatProfileContainer.getPercentAtRow(row));
return flatProfileContainer.getPercentAtRow(row);
case 2:
return StringUtils.mcsTimeToString(flatProfileContainer.getTimeInMcs0AtRow(row)) + " ms (" // NOI18N
+ percentFormat.format(flatProfileContainer.getPercentAtRow(row) / 100) + ")"; // NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ private String getNodeName(PrestimeCPUCCTNode pNode) {
}

private Float getNodeTimeRel(PrestimeCPUCCTNode pNode) {
return new Float(pNode.getTotalTime0InPerCent());
return pNode.getTotalTime0InPerCent();
}

private String getNodeTime(PrestimeCPUCCTNode pNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ private String getNodeName(PrestimeCPUCCTNode pNode) {
}

private Float getNodeTimeRel(PrestimeCPUCCTNode pNode) {
return new Float(pNode.getTotalTime0InPerCent());
return pNode.getTotalTime0InPerCent();
}

private String getNodeTime(PrestimeCPUCCTNode pNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private Object generateDefaultValue() {
} else if (type == Long.class || type == Long.TYPE) {
return new Long(0);
} else if (type == Float.class || type == Float.TYPE) {
return new Float(0);
return 0F;
} else if (type == Double.class || type == Double.TYPE) {
return new Double(0);
} else if (type == Boolean.class || type == Boolean.TYPE) {
Expand Down

0 comments on commit 190ffcb

Please sign in to comment.