[TECHBOT]

-Keep Command instances.
This avoids parsing files every time a command is received.

svn path=/trunk/irc/; revision=2139
This commit is contained in:
Sylvain Petreolle 2014-09-22 12:49:06 +00:00
parent 9f7d5915b5
commit 467c521f85

View File

@ -11,6 +11,8 @@ namespace TechBot.Library
private string m_CommandName;
private string m_CommandHelp;
private string m_CommandDesc;
private Command m_Instance;
object Lock = new object();
public CommandBuilder(Type commandType)
{
@ -46,7 +48,17 @@ namespace TechBot.Library
public Command CreateCommand()
{
return (Command)Type.Assembly.CreateInstance(Type.FullName, true);
// Create command instance and keep it for future uses.
lock (Lock)
{
if (m_Instance != null)
return m_Instance;
else
{
m_Instance = (Command)Type.Assembly.CreateInstance(Type.FullName, true);
return m_Instance;
}
}
}
}
}