Compile the regex that extract categories for colourization just once rather than on every single log.

Compiling every time is unnecessary since Regex is thread-safe.
bullet-2.82
Justin Clark-Casey (justincc) 2014-05-23 21:09:48 +01:00
parent fbcb76383d
commit f55e153636
1 changed files with 7 additions and 5 deletions

View File

@ -46,6 +46,11 @@ namespace OpenSim.Framework.Console
// private readonly object m_syncRoot = new object(); // private readonly object m_syncRoot = new object();
private const string LOGLEVEL_NONE = "(none)"; private const string LOGLEVEL_NONE = "(none)";
// Used to extract categories for colourization.
private Regex m_categoryRegex
= new Regex(
@"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)", RegexOptions.Singleline | RegexOptions.Compiled);
private int m_cursorYPosition = -1; private int m_cursorYPosition = -1;
private int m_cursorXPosition = 0; private int m_cursorXPosition = 0;
private StringBuilder m_commandLine = new StringBuilder(); private StringBuilder m_commandLine = new StringBuilder();
@ -280,11 +285,8 @@ namespace OpenSim.Framework.Console
string outText = text; string outText = text;
if (level != LOGLEVEL_NONE) if (level != LOGLEVEL_NONE)
{ {
string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)"; MatchCollection matches = m_categoryRegex.Matches(text);
Regex RE = new Regex(regex, RegexOptions.Singleline);
MatchCollection matches = RE.Matches(text);
if (matches.Count == 1) if (matches.Count == 1)
{ {