Avoid string allocations in some Concat overloads
authorJames Ko <jamesqko@gmail.com>
Sat, 20 Feb 2016 23:47:24 +0000 (18:47 -0500)
committerJames Ko <jamesqko@gmail.com>
Sat, 20 Feb 2016 23:47:24 +0000 (18:47 -0500)
Commit migrated from https://github.com/dotnet/coreclr/commit/b99e5c1638a7e909c918be313ef386b7d0ccb3c3

src/coreclr/src/mscorlib/src/System/String.cs

index 72089b0..f544fc9 100644 (file)
@@ -3237,20 +3237,19 @@ namespace System {
                 (str2 == null ? 0 : str2.Length));
             Contract.EndContractBlock();
 
-            if (str0==null && str1==null && str2==null) {
-                return String.Empty;
-            }
-
-            if (str0==null) {
-                str0 = String.Empty;
+            if (IsNullOrEmpty(str0))
+            {
+                return Concat(str1, str2);
             }
 
-            if (str1==null) {
-                str1 = String.Empty;
+            if (IsNullOrEmpty(str1))
+            {
+                return Concat(str0, str2);
             }
 
-            if (str2 == null) {
-                str2 = String.Empty;
+            if (IsNullOrEmpty(str2))
+            {
+                return Concat(str0, str1);
             }
 
             int totalLength = str0.Length + str1.Length + str2.Length;
@@ -3273,24 +3272,24 @@ namespace System {
                 (str3 == null ? 0 : str3.Length));
             Contract.EndContractBlock();
 
-            if (str0==null && str1==null && str2==null && str3==null) {
-                return String.Empty;
+            if (IsNullOrEmpty(str0))
+            {
+                return Concat(str1, str2, str3);
             }
 
-            if (str0==null) {
-                str0 = String.Empty;
+            if (IsNullOrEmpty(str1))
+            {
+                return Concat(str0, str2, str3);
             }
 
-            if (str1==null) {
-                str1 = String.Empty;
+            if (IsNullOrEmpty(str2))
+            {
+                return Concat(str0, str1, str3);
             }
 
-            if (str2 == null) {
-                str2 = String.Empty;
-            }
-            
-            if (str3 == null) {
-                str3 = String.Empty;
+            if (IsNullOrEmpty(str3))
+            {
+                return Concat(str0, str1, str2);
             }
 
             int totalLength = str0.Length + str1.Length + str2.Length + str3.Length;