SortedSet: Enable set comparision operations on views, and improve performance
[mono.git] / mcs / class / System / System.Text.RegularExpressions / interpreter.cs
index 9b51789fc8156c6b07eef010c61ef59ae8f4ae0b..0edc3239f6b177cb4c614ae99b2617dc553c2b04 100644 (file)
@@ -34,7 +34,7 @@ using System.Globalization;
 
 namespace System.Text.RegularExpressions {
 
-       class Interpreter : IMachine {
+       partial class Interpreter : BaseMachine {
                private int ReadProgramCount (int ptr)
                {
                        int ret = program [ptr + 1];
@@ -61,7 +61,7 @@ namespace System.Text.RegularExpressions {
 
                // IMachine implementation
 
-               public Match Scan (Regex regex, string text, int start, int end) {
+               public override Match Scan (Regex regex, string text, int start, int end) {
                        this.text = text;
                        this.text_end = end;
                        this.scan_ptr = start;
@@ -167,11 +167,10 @@ namespace System.Text.RegularExpressions {
                                                //      True
                                 
                                                bool reverse = ((OpFlags)program[pc + 3] & OpFlags.RightToLeft) != 0;
-                                               string substring = GetString (pc + 3);
 
                                                if (qs == null) {
                                                        bool ignore = ((OpFlags)program[pc + 3] & OpFlags.IgnoreCase) != 0;
-
+                                                       string substring = GetString (pc + 3);
                                                        qs = new QuickSearch (substring, ignore, reverse);
                                                }
                                                while ((anch_reverse && anch_ptr >= anch_begin) 
@@ -181,7 +180,7 @@ namespace System.Text.RegularExpressions {
                                                        {
                                                                anch_ptr = qs.Search (text, anch_ptr, anch_begin);
                                                                if (anch_ptr != -1)
-                                                                       anch_ptr += substring.Length ;
+                                                                       anch_ptr += qs.Length ;
                                                                
                                                        }
                                                        else
@@ -306,12 +305,13 @@ namespace System.Text.RegularExpressions {
                                                goto Fail;
 
                                        pc += 2;
-                                       for (int i = 0; i < len; ++ i) {
-                                               if (ignore) {
+                                       if (ignore) {
+                                               for (int i = 0; i < len; ++ i) {
                                                        if (Char.ToLower (text[ptr + i]) != Char.ToLower (text[str + i]))
                                                                goto Fail;
                                                }
-                                               else {
+                                       } else {
+                                               for (int i = 0; i < len; ++ i) {
                                                        if (text[ptr + i] != text[str + i])
                                                                goto Fail;
                                                }
@@ -1016,6 +1016,11 @@ namespace System.Text.RegularExpressions {
                        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);