Mercurial > projects > dwt-addons
diff dwtx/draw2d/ManhattanConnectionRouter.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 |
line wrap: on
line diff
--- a/dwtx/draw2d/ManhattanConnectionRouter.d Sun Aug 03 03:07:30 2008 +0200 +++ b/dwtx/draw2d/ManhattanConnectionRouter.d Sun Aug 03 17:01:51 2008 +0200 @@ -46,15 +46,42 @@ } } -private static Ray UP, DOWN, LEFT, RIGHT; +private static Ray UP_, DOWN_, LEFT_, RIGHT_; +private static Ray UP(){ + if( !initStaticCtor_done ) initStaticCtor(); + assert(UP_); + return UP_; +} +private static Ray DOWN(){ + if( !initStaticCtor_done ) initStaticCtor(); + assert(DOWN_); + return DOWN_; +} +private static Ray LEFT(){ + if( !initStaticCtor_done ) initStaticCtor(); + assert(LEFT_); + return LEFT_; +} +private static Ray RIGHT(){ + if( !initStaticCtor_done ) initStaticCtor(); + assert(RIGHT_); + return RIGHT_; +} + +private static bool initStaticCtor_done = false; +private static void initStaticCtor(){ + synchronized( ManhattanConnectionRouter.classinfo ){ + if( !initStaticCtor_done ){ + UP_ = new Ray(0, -1); + DOWN_ = new Ray(0, 1); + LEFT_ = new Ray(-1, 0); + RIGHT_ = new Ray(1, 0); + initStaticCtor_done = true; + } + } +} -static this(){ - UP = new Ray(0, -1); - DOWN = new Ray(0, 1); - LEFT = new Ray(-1, 0); - RIGHT = new Ray(1, 0); -} public this(){ rowsUsed = new HashMap();