diff dwtx/draw2d/ScaledGraphics.d @ 103:2d6540440fe6

Replace static ctors with lazy init.
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 17:01:51 +0200
parents 95307ad235d9
children c3583c6ec027
line wrap: on
line diff
--- a/dwtx/draw2d/ScaledGraphics.d	Sun Aug 03 03:07:30 2008 +0200
+++ b/dwtx/draw2d/ScaledGraphics.d	Sun Aug 03 17:01:51 2008 +0200
@@ -122,23 +122,21 @@
     }
 }
 
-private static int[][] intArrayCache;
-private final Rectangle tempRECT;
-
-static this(){
-    intArrayCache = new int[][](8);
-    for (int i = 0; i < intArrayCache.length; i++)
-        intArrayCache[i] = new int[i + 1];
+private static int[][] intArrayCache_;
+private static int[][] intArrayCache(){
+    if( intArrayCache_ is null ){
+        synchronized( ScaledGraphics.classinfo ){
+            if( intArrayCache_ is null ){
+                intArrayCache_ = new int[][](8);
+                for (int i = 0; i < intArrayCache_.length; i++)
+                    intArrayCache_[i] = new int[i + 1];
+            }
+        }
+    }
+    return intArrayCache_;
 }
-private void instanceInit(){
-    tempRECT = new Rectangle();
-    localCache = new FontHeightCache();
-    targetCache = new FontHeightCache();
-    stack = new ArrayList();
-    fontKey = new FontKey();
-    fontDataCache = new HashMap();
-    fontCache = new HashMap();
-}
+private const Rectangle tempRECT;
+
 private bool allowText = true;
 //private static final Point PT = new Point();
 private Map fontCache;
@@ -161,7 +159,15 @@
  * @param g the base graphics object
  */
 public this(Graphics g) {
-    instanceInit();
+    // instance init
+    tempRECT = new Rectangle();
+    localCache = new FontHeightCache();
+    targetCache = new FontHeightCache();
+    stack = new ArrayList();
+    fontKey = new FontKey();
+    fontDataCache = new HashMap();
+    fontCache = new HashMap();
+
     graphics = g;
     localFont = g.getFont();
     localLineWidth = g.getLineWidth();