8160721: Avoid deoptimizations in Font.equals.
authorgoetz
Fri, 01 Jul 2016 15:50:03 +0200
changeset 39866 ad2a71a4f495
parent 39865 62db9aaff554
child 39867 889e919f632e
8160721: Avoid deoptimizations in Font.equals. Reviewed-by: forax, simonis
jdk/src/java.desktop/share/classes/java/awt/Font.java
--- a/jdk/src/java.desktop/share/classes/java/awt/Font.java	Fri Jul 15 15:30:15 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/Font.java	Fri Jul 01 15:50:03 2016 +0200
@@ -1813,35 +1813,31 @@
             return true;
         }
 
-        if (obj != null) {
-            try {
-                Font font = (Font)obj;
-                if (size == font.size &&
-                    style == font.style &&
-                    nonIdentityTx == font.nonIdentityTx &&
-                    hasLayoutAttributes == font.hasLayoutAttributes &&
-                    pointSize == font.pointSize &&
-                    name.equals(font.name)) {
+        if (obj instanceof Font) {
+            Font font = (Font)obj;
+            if (size == font.size &&
+                style == font.style &&
+                nonIdentityTx == font.nonIdentityTx &&
+                hasLayoutAttributes == font.hasLayoutAttributes &&
+                pointSize == font.pointSize &&
+                name.equals(font.name)) {
 
-                    /* 'values' is usually initialized lazily, except when
-                     * the font is constructed from a Map, or derived using
-                     * a Map or other values. So if only one font has
-                     * the field initialized we need to initialize it in
-                     * the other instance and compare.
-                     */
-                    if (values == null) {
-                        if (font.values == null) {
-                            return true;
-                        } else {
-                            return getAttributeValues().equals(font.values);
-                        }
+                /* 'values' is usually initialized lazily, except when
+                 * the font is constructed from a Map, or derived using
+                 * a Map or other values. So if only one font has
+                 * the field initialized we need to initialize it in
+                 * the other instance and compare.
+                 */
+                if (values == null) {
+                    if (font.values == null) {
+                        return true;
                     } else {
-                        return values.equals(font.getAttributeValues());
+                        return getAttributeValues().equals(font.values);
                     }
+                } else {
+                    return values.equals(font.getAttributeValues());
                 }
             }
-            catch (ClassCastException e) {
-            }
         }
         return false;
     }