Author: zoltan
Date: 2008-02-10 13:08:27 -0500 (Sun, 10 Feb 2008)
New Revision: 95394
Modified:
trunk/mcs/class/System/System.Text.RegularExpressions/BaseMachine.cs
trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
trunk/mcs/class/System/System.Text.RegularExpressions/Group.cs
trunk/mcs/class/System/System.Text.RegularExpressions/Match.cs
trunk/mcs/class/System/System.Text.RegularExpressions/interpreter.cs
trunk/mcs/class/System/System.Text.RegularExpressions/replace.cs
Log:
2008-02-10 Zoltan Varga <[EMAIL PROTECTED]>
* replace.cs (NeedsGroupsOrCaptures): New property. Determines whenever
the
replacement process needs access to the groups or captures properties
of the
Match object.
* Group.cs: Add an internal ctor which avoids allocations.
* Match.cs: Ditto.
* BaseMachine.cs interpreter.cs: Add an optimization to avoid fully
creating
Match objects during Replace () if the replacement string is simple.
Modified: trunk/mcs/class/System/System.Text.RegularExpressions/BaseMachine.cs
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/BaseMachine.cs
2008-02-10 18:04:09 UTC (rev 95393)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/BaseMachine.cs
2008-02-10 18:08:27 UTC (rev 95394)
@@ -44,7 +44,7 @@
if (regex.RightToLeft)
return RTLReplace (regex, input, new
MatchEvaluator (ev.Evaluate), count, startat);
else
- return LTRReplace (regex, input, new
MatchAppendEvaluator (ev.EvaluateAppend), count, startat);
+ return LTRReplace (regex, input, new
MatchAppendEvaluator (ev.EvaluateAppend), count, startat,
ev.NeedsGroupsOrCaptures);
}
virtual public string [] Split (Regex regex, string input, int
count, int startat)
@@ -100,8 +100,14 @@
return ReplacementEvaluator.Evaluate (replacement,
match);
}
- internal string LTRReplace (Regex regex, string input,
MatchAppendEvaluator evaluator, int count, int startat)
+ internal string LTRReplace (Regex regex, string input,
MatchAppendEvaluator evaluator, int count, int startat) {
+ return LTRReplace (regex, input, evaluator, count,
startat, true);
+ }
+
+ internal string LTRReplace (Regex regex, string input,
MatchAppendEvaluator evaluator, int count, int startat, bool
needs_groups_or_captures)
{
+ this.needs_groups_or_captures =
needs_groups_or_captures;
+
Match m = Scan (regex, input, startat, input.Length);
if (!m.Success)
return input;
@@ -164,5 +170,10 @@
return result.ToString ();
}
+
+ // Specify whenever Match objects created by this machine need
to be fully
+ // built. If false, these can be omitted, avoiding some memory
allocations and
+ // processing time.
+ protected bool needs_groups_or_captures = true;
}
}
Modified: trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
2008-02-10 18:04:09 UTC (rev 95393)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
2008-02-10 18:08:27 UTC (rev 95394)
@@ -1,5 +1,16 @@
2008-02-10 Zoltan Varga <[EMAIL PROTECTED]>
+ * replace.cs (NeedsGroupsOrCaptures): New property. Determines whenever
the
+ replacement process needs access to the groups or captures properties
of the
+ Match object.
+
+ * Group.cs: Add an internal ctor which avoids allocations.
+
+ * Match.cs: Ditto.
+
+ * BaseMachine.cs interpreter.cs: Add an optimization to avoid fully
creating
+ Match objects during Replace () if the replacement string is simple.
+
* BaseMachine.cs Regex.cs: Make LTRReplace and RTLReplace instance
methods to
avoid creating two machines for each Regex.Replace () call.
Modified: trunk/mcs/class/System/System.Text.RegularExpressions/Group.cs
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/Group.cs
2008-02-10 18:04:09 UTC (rev 95393)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/Group.cs
2008-02-10 18:08:27 UTC (rev 95394)
@@ -57,6 +57,11 @@
captures = new CaptureCollection (n_caps);
captures.SetValue (this, n_caps - 1);
}
+
+ internal Group (string text, int index, int length) : base
(text, index, length)
+ {
+ success = true;
+ }
internal Group () : base ("")
{
Modified: trunk/mcs/class/System/System.Text.RegularExpressions/Match.cs
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/Match.cs
2008-02-10 18:04:09 UTC (rev 95393)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/Match.cs
2008-02-10 18:08:27 UTC (rev 95394)
@@ -85,6 +85,14 @@
}
#if !TARGET_JVM
internal Match (Regex regex, IMachine machine, string text, int
text_length, int n_groups,
+ int index, int length) :
+ base (text, index, length) {
+ this.regex = regex;
+ this.machine = machine;
+ this.text_length = text_length;
+ }
+
+ internal Match (Regex regex, IMachine machine, string text, int
text_length, int n_groups,
int index, int length, int n_caps) :
base (text, index, length, n_caps)
{
Modified: trunk/mcs/class/System/System.Text.RegularExpressions/interpreter.cs
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/interpreter.cs
2008-02-10 18:04:09 UTC (rev 95393)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/interpreter.cs
2008-02-10 18:08:27 UTC (rev 95394)
@@ -1016,6 +1016,11 @@
int n_caps, first_mark_index;
Group g;
GetGroupInfo (0, out first_mark_index, out n_caps);
+
+ // Avoid fully populating the Match instance if not
needed
+ if (!needs_groups_or_captures)
+ return new Match (regex, this, text, text_end,
0, marks [first_mark_index].Index, marks [first_mark_index].Length);
+
Match retval = new Match (regex, this, text, text_end,
groups.Length,
marks
[first_mark_index].Index, marks [first_mark_index].Length, n_caps);
PopulateGroup (retval, first_mark_index, n_caps);
Modified: trunk/mcs/class/System/System.Text.RegularExpressions/replace.cs
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/replace.cs
2008-02-10 18:04:09 UTC (rev 95393)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/replace.cs
2008-02-10 18:08:27 UTC (rev 95394)
@@ -87,6 +87,15 @@
}
}
+ public bool NeedsGroupsOrCaptures {
+ get {
+ if (n_pieces == 0)
+ return false;
+ else
+ return true;
+ }
+ }
+
void Ensure (int size)
{
int new_size;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches