* UrlUtils.cs: optimized string.Replace in RemoveDoubleSlashes
authorVladimir Krasnov <krasnov@mono-cvs.ximian.com>
Sun, 19 Aug 2007 12:53:58 +0000 (12:53 -0000)
committerVladimir Krasnov <krasnov@mono-cvs.ximian.com>
Sun, 19 Aug 2007 12:53:58 +0000 (12:53 -0000)
svn path=/trunk/mcs/; revision=84392

mcs/class/System.Web/System.Web.Util/ChangeLog
mcs/class/System.Web/System.Web.Util/UrlUtils.cs

index b430f6e52ac988d9b3096377e90c8fba2946a5e2..fabe445ea42b00f75d9a3450549c7af5a5f3ba5e 100644 (file)
@@ -1,3 +1,7 @@
+2006-08-19  Vladimir Krasnov  <vladimirk@mainsoft.com>
+
+       * UrlUtils.cs: optimized string.Replace in RemoveDoubleSlashes
+
 2007-03-21  Konstantin Triger <kostat@mainsoft.com>
 
        AltSerialization.cs: refactoring for Serialize/Deserialize functionality.
index cb2e7698394efcd2ef28f2461684ab2586b183eb..e387bc61e676710ff03fe56bcf77bbcbf2c7a928 100644 (file)
@@ -30,6 +30,7 @@
 //
 
 using System.Web.SessionState;
+using System.Text;
 namespace System.Web.Util {
        
        internal class UrlUtils {
@@ -199,13 +200,33 @@ namespace System.Web.Util {
                internal static string RemoveDoubleSlashes (string input)
                {
                        // MS VirtualPathUtility removes duplicate '/'
-                       string str = input;
-                       string x;
-                       while ((x = str.Replace ("//", "/")) != str) {
-                               str = x;
+
+                       int index = -1;
+                       for (int i = 1; i < input.Length; i++)
+                               if (input [i] == '/' && input [i - 1] == '/') {
+                                       index = i - 1;
+                                       break;
+                               }
+
+                       if (index == -1) // common case optimization
+                               return input;
+
+                       StringBuilder sb = new StringBuilder (input.Length);
+                       sb.Append (input, 0, index);
+
+                       for (int i = index; i < input.Length; i++) {
+                               if (input [i] == '/') {
+                                       int next = i + 1;
+                                       if (next < input.Length && input [next] == '/')
+                                               continue;
+                                       sb.Append ('/');
+                               }
+                               else {
+                                       sb.Append (input [i]);
+                               }
                        }
 
-                       return str;
+                       return sb.ToString ();
                }
 #endif