# HG changeset patch # User goetz # Date 1467381003 -7200 # Node ID ad2a71a4f495d1ee4847af0d8e2b0ae4348c0443 # Parent 62db9aaff5541c3cf629e9bacb3d5a42d7dc03f2 8160721: Avoid deoptimizations in Font.equals. Reviewed-by: forax, simonis diff -r 62db9aaff554 -r ad2a71a4f495 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; }