Browse Source

2001-09-08 Jeffrey Stedfast <[email protected]>

	* String.cs (TrimStart): Don't keep looping through the trimchars
	once we've found a match.
	(TrimEnd): Same here.
	(Trim): And finally here.

svn path=/trunk/mcs/; revision=767
Jeffrey Stedfast 24 years ago
parent
commit
2bac0ddf51
2 changed files with 23 additions and 4 deletions
  1. 7 0
      mcs/class/corlib/System/ChangeLog
  2. 16 4
      mcs/class/corlib/System/String.cs

+ 7 - 0
mcs/class/corlib/System/ChangeLog

@@ -1,3 +1,10 @@
+2001-09-08  Jeffrey Stedfast  <[email protected]>
+
+	* String.cs (TrimStart): Don't keep looping through the trimchars
+	once we've found a match.
+	(TrimEnd): Same here.
+	(Trim): And finally here.
+
 2001-09-07  Ravi Pratap  <[email protected]>
 
 	* Char.cs (IsLetterOrDigit): Implement.

+ 16 - 4
mcs/class/corlib/System/String.cs

@@ -1534,8 +1534,11 @@ namespace System {
 			for (begin = 0; matches && begin < this.length; begin++) {
 				if (trimChars != null) {
 					matches = false;
-					foreach (char c in trimChars)
+					foreach (char c in trimChars) {
 						matches = this.c_str[begin] == c;
+						if (matches)
+							break;
+					}
 				} else {
 					matches = is_lwsp (this.c_str[begin]);
 				}
@@ -1545,8 +1548,11 @@ namespace System {
 			for (end = this.length; end > begin; end--) {
 				if (trimChars != null) {
 					matches = false;
-					foreach (char c in trimChars)
+					foreach (char c in trimChars) {
 						matches = this.c_str[end] == c;
+						if (matches)
+							break;
+					}
 				} else {
 					matches = is_lwsp (this.c_str[end]);
 				}
@@ -1566,8 +1572,11 @@ namespace System {
 			for (end = this.length; end > 0; end--) {
 				if (trimChars != null) {
 					matches = false;
-					foreach (char c in trimChars)
+					foreach (char c in trimChars) {
 						matches = this.c_str[end] == c;
+						if (matches)
+							break;
+					}
 				} else {
 					matches = is_lwsp (this.c_str[end]);
 				}
@@ -1587,8 +1596,11 @@ namespace System {
 			for (begin = 0; matches && begin < this.length; begin++) {
 				if (trimChars != null) {
 					matches = false;
-					foreach (char c in trimChars)
+					foreach (char c in trimChars) {
 						matches = this.c_str[begin] == c;
+						if (matches)
+							break;
+					}
 				} else {
 					matches = is_lwsp (this.c_str[begin]);
 				}