Skip to content

Commit

Permalink
Merge pull request microsoft#1150 from brianrob/regex
Browse files Browse the repository at this point in the history
Undo Revert of Regex Compilation
  • Loading branch information
brianrob authored Apr 8, 2020
2 parents 39f0940 + f0d1094 commit fc1d255
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/PerfView/EtwEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ internal ETWEventRecord(ETWEventSource source, TraceEvent data, Dictionary<strin

#region private

private static readonly Regex specialCharRemover = new Regex(" *[\r\n\t]+ *", RegexOptions.Compiled);

/// <summary>
/// Adds 'fieldName' with value 'fieldValue' to the output. It either goes into a column (based on columnOrder) or it goes into
/// 'rest' as a fieldName="fieldValue" string. It also updates 'columnSums' for the fieldValue for any in a true column
Expand All @@ -658,7 +660,7 @@ private void AddField(string fieldName, string fieldValue, Dictionary<string, in
}
// If the field value has to many newlines in it, the GUI gets confused because the text block is larger than
// the vertical size. WPF may fix this at some point, but in the mean time this is a work around.
fieldValue = Regex.Replace(fieldValue, " *[\r\n\t]+ *", " ");
fieldValue = specialCharRemover.Replace(fieldValue, " ");

var putInRest = true;
if (columnOrder != null)
Expand Down
4 changes: 3 additions & 1 deletion src/TraceEvent/DynamicTraceEventParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ protected internal override Delegate Target
}
}

private static readonly Regex paramReplacer = new Regex(@"%(\d+)", RegexOptions.Compiled);

public override string GetFormattedMessage(IFormatProvider formatProvider)
{
if (MessageFormat == null)
Expand All @@ -1027,7 +1029,7 @@ public override string GetFormattedMessage(IFormatProvider formatProvider)

// TODO is this error handling OK?
// Replace all %N with the string value for that parameter.
return Regex.Replace(MessageFormat, @"%(\d+)", delegate (Match m)
return paramReplacer.Replace(MessageFormat, delegate (Match m)
{
int targetIndex = int.Parse(m.Groups[1].Value) - 1;

Expand Down

0 comments on commit fc1d255

Please sign in to comment.