FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Patch: Improve MDGlobalState

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
Roosmaa



Joined: 05 Nov 2006
Posts: 9
Location: Estonia

PostPosted: Sun Nov 05, 2006 3:54 pm    Post subject: Patch: Improve MDGlobalState Reply with quote

At the moment the MDGlobalState class doesn't implement the singleton pattern as well as it could, my suggestion (as a patch file):

Code:
--- state.d.orig   2006-11-05 23:49:05.000000000 +0200
+++ state.d   2006-11-05 23:49:08.000000000 +0200
@@ -12,34 +12,24 @@
 
 class MDGlobalState
 {
-   public static MDGlobalState instance;
+   private static MDGlobalState instance;
    private MDState mMainThread;
    private MDTable[] mBasicTypeMT;
 
    public static MDGlobalState opCall()
    {
-      debug if(instance is null)
-         throw new MDException("MDGlobalState is not initialized");
+      if(instance is null)
+         instance = new MDGlobalState();
 
       return instance;
-   }
-
-   public static void initialize()
-   {
-      instance = new MDGlobalState();
-   }
-
-   public this()
+   }
+   
+   private this()
    {
-      if(instance !is null)
-         throw new MDException("MDGlobalState is a singleton and cannot be created more than once");
-
       mMainThread = new MDState();
       mBasicTypeMT = new MDTable[MDValue.Type.max + 1];
-
-      instance = this;
-   }
-
+   }
+   
    public MDTable getMetatable(MDValue.Type type)
    {
       return mBasicTypeMT[cast(uint)type];


P.S: Only file which needs to be modified after that patch is test.d ... Everything else should work perfectly (probably even better than before, as now you can't forget to initialize MDGlobalState)
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Sun Nov 05, 2006 4:04 pm    Post subject: Reply with quote

Thanks, I've rolled it in.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group