Refactored ifs into switches.
authorMarcos Henrich <marcos.henrich@xamarin.com>
Fri, 25 Jul 2014 13:47:54 +0000 (14:47 +0100)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Fri, 25 Jul 2014 13:47:54 +0000 (14:47 +0100)
mcs/class/System/System/Uri.cs
mcs/class/System/System/UriHelper.cs

index 41eb20c82990a595e08da0bc7f3cf5175ecd15c2..38b95c49614af154d68c97c16ebc633709e70912 100644 (file)
@@ -1769,19 +1769,34 @@ namespace System {
                //
                static bool NeedToEscapeDataChar (char b)
                {
-                       if (IriParsing) {
-                               // .NET 4.0 follows RFC 3986 Unreserved Characters
-                               return !((b >= 'A' && b <= 'Z') ||
-                                        (b >= 'a' && b <= 'z') ||
-                                        (b >= '0' && b <= '9') ||
-                                        b == '-' || b == '.' || b == '_' || b == '~');
+                       if ((b >= 'A' && b <= 'Z') ||
+                               (b >= 'a' && b <= 'z') ||
+                               (b >= '0' && b <= '9'))
+                               return false;
+
+                       switch (b) {
+                       case '-':
+                       case '.':
+                       case '_':
+                       case '~':
+                               return false;
+                       }
+
+                       if (IriParsing)
+                               return true;
+
+                       switch (b) {
+                       case '!':
+                       case '\'':
+                       case '(':
+                       case ')':
+                       case '*':
+                       case '-':
+                       case '.':
+                               return false;
                        }
 
-                       return !((b >= 'A' && b <= 'Z') ||
-                                (b >= 'a' && b <= 'z') ||
-                                (b >= '0' && b <= '9') ||
-                                b == '_' || b == '~' || b == '!' || b == '\'' ||
-                                b == '(' || b == ')' || b == '*' || b == '-' || b == '.');
+                       return true;
                }
                
                public static string EscapeDataString (string stringToEscape)
@@ -1820,14 +1835,26 @@ namespace System {
                //
                static bool NeedToEscapeUriChar (char b)
                {
-                       if ((b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') || (b >= '&' && b <= ';') ||
-                               b == '!' || b == '#' || b == '$' || b == '=' || b == '?' || b == '@' || b == '_' || b == '~')
+                       if ((b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z') || (b >= '&' && b <= ';'))
                                return false;
 
+                       switch (b) {
+                       case '!':
+                       case '#':
+                       case '$':
+                       case '=':
+                       case '?':
+                       case '@':
+                       case '_':
+                       case '~':
+                               return false;
 #if NET_4_0
-                       if (b == '[' || b == ']')
+                       case '[':
+                       case ']':
                                return !IriParsing;
 #endif
+                       }
+
                        return true;
                }
                
index 5fe4f3001720fd28cf82a6c2f459948693039ae9..173eae32725d1bc919dfff1647b7723271af2636 100644 (file)
@@ -363,24 +363,49 @@ namespace System {
                                if (uriKind == UriKind.Relative)
                                        return false;
 
-                               if (c == '$' || c == '&' || c == '+' || c == ',' || c == ';' || c == '=' || c == '@')
+                               switch (c) {
+                               case '$':
+                               case '&':
+                               case '+':
+                               case ',':
+                               case ';':
+                               case '=':
+                               case '@':
                                        return true;
+                               }
 
                                if (c < 0x20 || c == 0x7f)
                                        return true;
                        }
 
                        if (uriFormat == UriFormat.SafeUnescaped || uriFormat == ToStringUnescape) {
-                               if (c == '-' || c == '.' || c == '_' || c == '~')
+                               switch (c) {
+                               case '-':
+                               case '.':
+                               case '_':
+                               case '~':
                                        return true;
-
-                               if (c == ' ' || c == '!' || c == '"' || c == '\'' || c == '(' || c == ')' || c == '*' ||
-                                       c == '<' || c == '>' || c == '^' || c == '`' || c == '{' || c == '}' || c == '|')
+                               case ' ':
+                               case '!':
+                               case '"':
+                               case '\'':
+                               case '(':
+                               case ')':
+                               case '*':
+                               case '<':
+                               case '>':
+                               case '^':
+                               case '`':
+                               case '{':
+                               case '}':
+                               case '|':
                                        return uriKind != UriKind.Relative ||
                                                (IriParsing && (formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0);
-
-                               if (c == ':' || c == '[' || c == ']')
+                               case ':':
+                               case '[':
+                               case ']':
                                        return uriKind != UriKind.Relative;
+                               }
 
                                if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))
                                        return true;
@@ -403,14 +428,28 @@ namespace System {
 
                                        return false;
                                }
-
-                               if (c == '-' || c == '.' || c == '_' || c == '~')
-                                       return true;
                                
-                               if ((formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0 &&
-                                       (c == '!' || c == '\'' || c == '(' || c == ')' || c == '*' ||
-                                       c == ':' || c == '[' || c == ']'))
+                               switch (c) {
+                               case '-':
+                               case '.':
+                               case '_':
+                               case '~':
                                        return true;
+                               }
+
+                               if ((formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0) {
+                                       switch (c) {
+                                       case '!':
+                                       case '\'':
+                                       case '(':
+                                       case ')':
+                                       case '*':
+                                       case ':':
+                                       case '[':
+                                       case ']':
+                                               return true;
+                                       }
+                               }
 
                                if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))
                                        return true;
@@ -468,14 +507,22 @@ namespace System {
                                if (c < 0x20 || c >= 0x7F)
                                        return component != UriComponents.Host;
 
-                               if (c == ' ' || c == '"' || c == '%' || c == '<' || c == '>' || c == '^' ||
-                                       c == '`' || c == '{' || c == '}' || c == '|')
+                               switch (c) {
+                               case ' ':
+                               case '"':
+                               case '%':
+                               case '<':
+                               case '>':
+                               case '^':
+                               case '`':
+                               case '{':
+                               case '}':
+                               case '|':
                                        return true;
-
-                               if (c == '[' || c == ']')
+                               case '[':
+                               case ']':
                                        return !IriParsing;
-
-                               if (c == '\\') {
+                               case '\\':
                                        return component != UriComponents.Path ||
                                                   SchemeContains (scheme,
                                                           UriSchemes.Gopher | UriSchemes.Ldap | UriSchemes.Mailto | UriSchemes.Nntp |