<Swing Dev> RFR : 8049893 Replace uses of 'new Integer()' with appropriate alternative across client classes

Otávio Gonçalves de Santana otaviopolianasantana at gmail.com
Fri Jul 11 11:08:16 UTC 2014


JInternalFrame
Because it has a method, line 1285, with int, setLayer(int), so it will
capture just to do boxing, so I forced the boxing to avoid this method and
go directly to setLayer(Integer), line 1254.

JlayeredPane
Done.

BasicLookAndFeel
Integer four //fixed
How was talked 500 is not in cached range.


On Fri, Jul 11, 2014 at 6:03 AM, Petr Pchelko <petr.pchelko at oracle.com>
wrote:

> 500 and 1000L are outside of the range [-127, 128]. Therefore they won't
> be cached.
>
> Agreed, that’s what I didn’t think about.
>
> With best regards. Petr.
>
> On Jul 11, 2014, at 1:00 PM, Andrej Golovnin <andrej.golovnin at gmail.com>
> wrote:
>
> Hi Petr,
>
> BasicLookAndFeel - making “shared Integers” and “shared longs” is
>> pointless after your fix. Please inline.
>>
>
> It's not pointless.
>
>  458         Integer fiveHundred = 500;
>  459
>  460         // *** Shared Longs
>  461         Long oneThousand = 1000L;
>
> 500 and 1000L are outside of the range [-127, 128]. Therefore they won't
> be cached.
>
> But this one:
>
> 676         Integer four = 4;
>
> can be indeed inlined.
>
> Best regards,
> Andrej Golovnin
>
>
>
>>
>> With best regards. Petr.
>>
>> On Jul 11, 2014, at 5:36 AM, Otávio Gonçalves de Santana <
>> otaviopolianasantana at gmail.com> wrote:
>>
>> https://bugs.openjdk.java.net/browse/JDK-8049893
>> http://cr.openjdk.java.net/~prr/8049893/
>>
>> --
>> Cheers!.
>>
>> Otávio Gonçalves de Santana
>>
>> blog:     http://otaviosantana.blogspot.com.br/
>> twitter: http://twitter.com/otaviojava
>> site:     *http://about.me/otaviojava <http://about.me/otaviojava>*
>> 55 (11) 98255-3513
>>
>>
>>
>
>


-- 
Cheers!.

Otávio Gonçalves de Santana

blog:     http://otaviosantana.blogspot.com.br/
twitter: http://twitter.com/otaviojava
site:     *http://about.me/otaviojava <http://about.me/otaviojava>*
55 (11) 98255-3513
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20140711/f085927c/attachment.html>
-------------- next part --------------
diff -r 2df45ac1bf49 src/share/classes/javax/swing/JLayeredPane.java
--- a/src/share/classes/javax/swing/JLayeredPane.java	Thu Jun 26 12:51:38 2014 -0700
+++ b/src/share/classes/javax/swing/JLayeredPane.java	Fri Jul 11 07:47:29 2014 -0300
@@ -158,15 +158,15 @@
 public class JLayeredPane extends JComponent implements Accessible {
     /// Watch the values in getObjectForLayer()
     /** Convenience object defining the Default layer. Equivalent to new Integer(0).*/
-    public final static Integer DEFAULT_LAYER = new Integer(0);
+    public final static Integer DEFAULT_LAYER = 0;
     /** Convenience object defining the Palette layer. Equivalent to new Integer(100).*/
-    public final static Integer PALETTE_LAYER = new Integer(100);
+    public final static Integer PALETTE_LAYER = 100;
     /** Convenience object defining the Modal layer. Equivalent to new Integer(200).*/
-    public final static Integer MODAL_LAYER = new Integer(200);
+    public final static Integer MODAL_LAYER = 200;
     /** Convenience object defining the Popup layer. Equivalent to new Integer(300).*/
-    public final static Integer POPUP_LAYER = new Integer(300);
+    public final static Integer POPUP_LAYER = 300;
     /** Convenience object defining the Drag layer. Equivalent to new Integer(400).*/
-    public final static Integer DRAG_LAYER = new Integer(400);
+    public final static Integer DRAG_LAYER = 400;
     /** Convenience object defining the Frame Content layer.
       * This layer is normally only use to position the contentPane and menuBar
       * components of JFrame.
@@ -293,10 +293,7 @@
       */
     public static void putLayer(JComponent c, int layer) {
         /// MAKE SURE THIS AND setLayer(Component c, int layer, int position)  are SYNCED
-        Integer layerObj;
-
-        layerObj = new Integer(layer);
-        c.putClientProperty(LAYER_PROPERTY, layerObj);
+        c.putClientProperty(LAYER_PROPERTY, layer);
     }
 
     /** Gets the layer property for a JComponent, it
@@ -608,27 +605,20 @@
      * @return an Integer object for that layer
      */
     protected Integer getObjectForLayer(int layer) {
-        Integer layerObj;
         switch(layer) {
         case 0:
-            layerObj = DEFAULT_LAYER;
-            break;
+            return DEFAULT_LAYER;
         case 100:
-            layerObj = PALETTE_LAYER;
-            break;
+            return PALETTE_LAYER;
         case 200:
-            layerObj = MODAL_LAYER;
-            break;
+            return MODAL_LAYER;
         case 300:
-            layerObj = POPUP_LAYER;
-            break;
+            return POPUP_LAYER;
         case 400:
-            layerObj = DRAG_LAYER;
-            break;
+            return DRAG_LAYER;
         default:
-            layerObj = new Integer(layer);
+            return layer;
         }
-        return layerObj;
     }
-------------- next part --------------
diff -r 2df45ac1bf49 src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java
--- a/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java	Thu Jun 26 12:51:38 2014 -0700
+++ b/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java	Fri Jul 11 07:47:29 2014 -0300
@@ -455,7 +455,7 @@
         initResourceBundle(table);
 
         // *** Shared Integers
-        Integer fiveHundred = new Integer(500);
+        Integer fiveHundred = 500;
 
         // *** Shared Longs
         Long oneThousand = new Long(1000);
@@ -673,7 +673,6 @@
         Object editorMargin = threeInsets;
 
         Object caretBlinkRate = fiveHundred;
-        Integer four = new Integer(4);
 
         Object[] allAuditoryCues = new Object[] {
                 "CheckBoxMenuItem.commandSound",
@@ -714,7 +713,7 @@
             "Button.highlight", controlLtHighlight,
             "Button.border", buttonBorder,
             "Button.margin", new InsetsUIResource(2, 14, 2, 14),
-            "Button.textIconGap", four,
+            "Button.textIconGap", 4,
             "Button.textShiftOffset", zero,
             "Button.focusInputMap", new UIDefaults.LazyInputMap(new Object[] {
                          "SPACE", "pressed",
@@ -732,7 +731,7 @@
             "ToggleButton.highlight", controlLtHighlight,
             "ToggleButton.border", buttonToggleBorder,
             "ToggleButton.margin", new InsetsUIResource(2, 14, 2, 14),
-            "ToggleButton.textIconGap", four,
+            "ToggleButton.textIconGap", 4,
             "ToggleButton.textShiftOffset", zero,
             "ToggleButton.focusInputMap",
               new UIDefaults.LazyInputMap(new Object[] {
@@ -749,7 +748,7 @@
             "RadioButton.highlight", controlLtHighlight,
             "RadioButton.border", radioButtonBorder,
             "RadioButton.margin", twoInsets,
-            "RadioButton.textIconGap", four,
+            "RadioButton.textIconGap", 4,
             "RadioButton.textShiftOffset", zero,
             "RadioButton.icon", radioButtonIcon,
             "RadioButton.focusInputMap",
@@ -764,7 +763,7 @@
             "CheckBox.foreground", controlText,
             "CheckBox.border", radioButtonBorder,
             "CheckBox.margin", twoInsets,
-            "CheckBox.textIconGap", four,
+            "CheckBox.textIconGap", 4,
             "CheckBox.textShiftOffset", zero,
             "CheckBox.icon", checkBoxIcon,
             "CheckBox.focusInputMap",
@@ -1087,10 +1086,10 @@
             "Menu.margin", twoInsets,
             "Menu.checkIcon", menuItemCheckIcon,
             "Menu.arrowIcon", menuArrowIcon,
-            "Menu.menuPopupOffsetX", new Integer(0),
-            "Menu.menuPopupOffsetY", new Integer(0),
-            "Menu.submenuPopupOffsetX", new Integer(0),
-            "Menu.submenuPopupOffsetY", new Integer(0),
+            "Menu.menuPopupOffsetX", 0,
+            "Menu.menuPopupOffsetY", 0,
+            "Menu.submenuPopupOffsetX", 0,
+            "Menu.submenuPopupOffsetY", 0,
             "Menu.shortcutKeys", new int[]{
                 SwingUtilities2.getSystemMnemonicKeyMask()
             },
@@ -1188,10 +1187,10 @@
             "ProgressBar.selectionForeground", control,
             "ProgressBar.selectionBackground", textHighlight,
             "ProgressBar.border", progressBarBorder,
-            "ProgressBar.cellLength", new Integer(1),
+            "ProgressBar.cellLength", 1,
             "ProgressBar.cellSpacing", zero,
-            "ProgressBar.repaintInterval", new Integer(50),
-            "ProgressBar.cycleTime", new Integer(3000),
+            "ProgressBar.repaintInterval", 50,
+            "ProgressBar.cycleTime", 3000,
             "ProgressBar.horizontalSize", new DimensionUIResource(146, 12),
             "ProgressBar.verticalSize", new DimensionUIResource(12, 146),
 
@@ -1236,7 +1235,7 @@
                         "LEFT", "positiveUnitIncrement",
                      "KP_LEFT", "positiveUnitIncrement",
                  }),
-            "ScrollBar.width", new Integer(16),
+            "ScrollBar.width", 16,
 
             "ScrollPane.font", dialogPlain12,
             "ScrollPane.background", control,
@@ -1332,7 +1331,7 @@
             "SplitPane.shadow", controlShadow,
             "SplitPane.darkShadow", controlDkShadow,
             "SplitPane.border", splitPaneBorder,
-            "SplitPane.dividerSize", new Integer(7),
+            "SplitPane.dividerSize", 7,
             "SplitPaneDivider.border", splitPaneDividerBorder,
             "SplitPaneDivider.draggingColor", darkGray,
             "SplitPane.ancestorInputMap",
@@ -1363,7 +1362,7 @@
             "TabbedPane.darkShadow", controlDkShadow,
             "TabbedPane.selected", null,
             "TabbedPane.focus", controlText,
-            "TabbedPane.textIconGap", four,
+            "TabbedPane.textIconGap", 4,
 
             // Causes tabs to be painted on top of the content area border.
             // The amount of overlap is then controlled by tabAreaInsets.bottom,
@@ -1377,7 +1376,7 @@
             "TabbedPane.selectedTabPadInsets", tabbedPaneTabPadInsets,
             "TabbedPane.tabAreaInsets", tabbedPaneTabAreaInsets,
             "TabbedPane.contentBorderInsets", tabbedPaneContentBorderInsets,
-            "TabbedPane.tabRunOverlay", new Integer(2),
+            "TabbedPane.tabRunOverlay", 2,
             "TabbedPane.tabsOpaque", Boolean.TRUE,
             "TabbedPane.contentOpaque", Boolean.TRUE,
             "TabbedPane.focusInputMap",
@@ -1737,9 +1736,9 @@
             "Tree.selectionBorderColor", black,
             "Tree.dropLineColor", controlShadow,
             "Tree.editorBorder", blackLineBorder,
-            "Tree.leftChildIndent", new Integer(7),
-            "Tree.rightChildIndent", new Integer(13),
-            "Tree.rowHeight", new Integer(16),
+            "Tree.leftChildIndent", 7,
+            "Tree.rightChildIndent", 13,
+            "Tree.rowHeight", 16,
             "Tree.scrollsOnExpand", Boolean.TRUE,
             "Tree.openIcon", SwingUtilities2.makeIcon(getClass(),
                                                       BasicLookAndFeel.class,


More information about the swing-dev mailing list