Roosmaa
Joined: 05 Nov 2006 Posts: 9 Location: Estonia
|
Posted: Sun Nov 05, 2006 3:54 pm Post subject: Patch: Improve MDGlobalState |
|
|
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) |
|