8210384: SunLayoutEngine.isAAT() font is expensive on MacOS
Reviewed-by: dmarkov, kaddepalli
--- a/src/java.desktop/share/classes/sun/font/SunLayoutEngine.java Sat Sep 08 12:32:51 2018 -0700
+++ b/src/java.desktop/share/classes/sun/font/SunLayoutEngine.java Sun Sep 09 11:19:57 2018 -0700
@@ -35,6 +35,7 @@
import java.lang.ref.SoftReference;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Locale;
+import java.util.WeakHashMap;
/*
* different ways to do this
@@ -148,17 +149,30 @@
this.key = key;
}
+ static WeakHashMap<Font2D, Boolean> aatInfo = new WeakHashMap<>();
+
private boolean isAAT(Font2D font) {
+ Boolean aatObj;
+ synchronized (aatInfo) {
+ aatObj = aatInfo.get(font);
+ }
+ if (aatObj != null) {
+ return aatObj.booleanValue();
+ }
+ boolean aat = false;
if (font instanceof TrueTypeFont) {
TrueTypeFont ttf = (TrueTypeFont)font;
- return ttf.getDirectoryEntry(TrueTypeFont.morxTag) != null ||
+ aat = ttf.getDirectoryEntry(TrueTypeFont.morxTag) != null ||
ttf.getDirectoryEntry(TrueTypeFont.mortTag) != null;
} else if (font instanceof PhysicalFont) {
PhysicalFont pf = (PhysicalFont)font;
- return pf.getTableBytes(TrueTypeFont.morxTag) != null ||
+ aat = pf.getTableBytes(TrueTypeFont.morxTag) != null ||
pf.getTableBytes(TrueTypeFont.mortTag) != null;
}
- return false;
+ synchronized (aatInfo) {
+ aatInfo.put(font, Boolean.valueOf(aat));
+ }
+ return aat;
}
public void layout(FontStrikeDesc desc, float[] mat, float ptSize, int gmask,