Minor code re-organization
authorRaja R Harinath <harinath@hurrynot.org>
Wed, 19 Aug 2009 20:41:51 +0000 (20:41 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Wed, 19 Aug 2009 20:41:51 +0000 (20:41 -0000)
* Regex.cs (group_numbers): New.
(GetGroupNumbers): Move array initialization ...
(GroupNumbers): ... to new on-demand initializer.

svn path=/trunk/mcs/; revision=140287

mcs/class/System/System.Text.RegularExpressions/ChangeLog
mcs/class/System/System.Text.RegularExpressions/Regex.cs

index 89fb1dbaf6bfbad09ccebc79fee8212550912a0e..708ca8c66971f13c12dc89fed94dc797f6afe837 100644 (file)
@@ -1,3 +1,9 @@
+2009-08-19  Raja R Harinath  <harinath@hurrynot.org>
+
+       * Regex.cs (group_numbers): New.
+       (GetGroupNumbers): Move array initialization ...
+       (GroupNumbers): ... to new on-demand initializer.
+
 2009-08-19  Raja R Harinath  <harinath@hurrynot.org>
 
        * Regex.cs (group_names): Rename from _groupNumbersToNameMap.
index 9ee0d3a6cb04539bc80d9dc7669bc208d93143e5..8cad895fbf15ec44495f1d49328697a596bced80 100644 (file)
@@ -306,12 +306,10 @@ namespace System.Text.RegularExpressions {
                        return names;
                }
 
-               public int[] GetGroupNumbers ()
+               public int [] GetGroupNumbers ()
                {
-                       int[] numbers = new int [1 + group_count];
-                       for (int i = 0; i <= group_count; ++i)
-                               numbers [i] = i;
-                       // FIXME: needs to handle arbitrarily numbered groups '(?<43>abc)'
+                       int [] numbers = new int [1 + group_count];
+                       Array.Copy (GroupNumbers, numbers, 1 + group_count);
                        return numbers;
                }
 
@@ -509,13 +507,26 @@ namespace System.Text.RegularExpressions {
                                group_names [(int) de.Value] = (string) de.Key;
                        return group_names;
                }
-               
+
+               private int [] GroupNumbers {
+                       get {
+                               if (group_numbers == null) {
+                                       group_numbers = new int [1 + group_count];
+                                       for (int i = 0; i <= group_count; ++i)
+                                               group_numbers [i] = i;
+                                       // FIXME: needs to handle arbitrarily numbered groups '(?<43>abc)'
+                                       return group_numbers;
+                               }
+                               return group_numbers;
+                       }
+               }
+
                private IMachineFactory machineFactory;
                private IDictionary mapping;
                private int group_count;
                private bool refsInitialized;
                private string [] group_names;
-
+               private int [] group_numbers;
                
                // protected members