Explorar el Código

2004-11-08 Ben Maurer <[email protected]>

	* replace.cs, parser.cs: Use stringbuilder for allocation sanity.

svn path=/trunk/mcs/; revision=35869
Ben Maurer hace 21 años
padre
commit
e2a91c4d71

+ 4 - 0
mcs/class/System/System.Text.RegularExpressions/ChangeLog

@@ -1,3 +1,7 @@
+2004-11-08  Ben Maurer  <[email protected]>
+
+	* replace.cs, parser.cs: Use stringbuilder for allocation sanity.
+
 2004-10-21 Joerg Rosenkranz <[email protected]>
 
     * regex.cs: Fixed a bug introduced with the last patch which

+ 3 - 3
mcs/class/System/System.Text.RegularExpressions/parser.cs

@@ -1048,7 +1048,7 @@ namespace System.Text.RegularExpressions.Syntax {
 			this.pattern = pattern;
 			this.ptr = 0;
 
-			string result = "";
+			StringBuilder result = new StringBuilder (pattern.Length);
 			while (ptr < pattern.Length) {
 				int c = pattern[ptr ++];
 				if (c == '\\') {
@@ -1060,10 +1060,10 @@ namespace System.Text.RegularExpressions.Syntax {
 							c = '\b';
 					}
 				}
-				result += (char)c;
+				result.Append (c);
 			}
 
-			return result;
+			return result.ToString ();
 		}
 
 		private void ResolveReferences () {

+ 5 - 5
mcs/class/System/System.Text.RegularExpressions/replace.cs

@@ -59,7 +59,7 @@ namespace System.Text.RegularExpressions {
 
 		private void Compile (string replacement) {
 			replacement = Parser.Unescape (replacement);
-			string literal = "";
+			StringBuilder literal = new StringBuilder ();
 
 			int ptr = 0;
 			char c;
@@ -75,18 +75,18 @@ namespace System.Text.RegularExpressions {
 				}
 
 				if (term != null) {
-					term.Literal = literal;
+					term.Literal = literal.ToString ();
 					terms.Add (term);
 
 					term = null;
-					literal = "";
+					literal.Length = 0;
 				}
 				else
-					literal += c;
+					literal.Append (c);
 			}
 
 			if (term == null && literal.Length > 0) {
-				terms.Add (new Term (literal));
+				terms.Add (new Term (literal.ToString ()));
 			}
 		}