6727719: Performance of TextLayout.getBounds()
authorprr
Thu, 12 Mar 2009 12:01:49 -0700
changeset 2390 080fb3a8be94
parent 2389 62115d5c2ed3
child 2391 3397fe90e591
6727719: Performance of TextLayout.getBounds() Reviewed-by: jgodinez, dougfelt
jdk/src/share/classes/sun/font/FileFontStrike.java
--- a/jdk/src/share/classes/sun/font/FileFontStrike.java	Thu Mar 05 10:56:06 2009 -0800
+++ b/jdk/src/share/classes/sun/font/FileFontStrike.java	Thu Mar 12 12:01:49 2009 -0700
@@ -842,8 +842,22 @@
         return fileFont.getGlyphOutlineBounds(pScalerContext, glyphCode);
     }
 
+    private ConcurrentHashMap<Integer, GeneralPath> outlineMap;
+
     GeneralPath getGlyphOutline(int glyphCode, float x, float y) {
-        return fileFont.getGlyphOutline(pScalerContext, glyphCode, x, y);
+        if (outlineMap == null) {
+            outlineMap = new ConcurrentHashMap<Integer, GeneralPath>();
+        }
+        GeneralPath gp = (GeneralPath)outlineMap.get(glyphCode);
+        if (gp == null) {
+            gp = fileFont.getGlyphOutline(pScalerContext, glyphCode, 0, 0);
+            outlineMap.put(glyphCode, gp);
+        }
+        gp = (GeneralPath)gp.clone(); // mutable!
+        if (x != 0f || y != 0f) {
+            gp.transform(AffineTransform.getTranslateInstance(x, y));
+        }
+        return gp;
     }
 
     GeneralPath getGlyphVectorOutline(int[] glyphs, float x, float y) {