From: Anirudh Agnihotry Date: Thu, 8 Feb 2018 00:49:31 +0000 (-0800) Subject: Removes Extra allocations for corner cases in CombineNochecks (#16255) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07ab3995979613b6f554fbad18bb43bdbf48c1ae;p=platform%2Fupstream%2Fcoreclr.git Removes Extra allocations for corner cases in CombineNochecks (#16255) * Added String Overload --- diff --git a/src/mscorlib/shared/System/IO/Path.cs b/src/mscorlib/shared/System/IO/Path.cs index 892cdafa59..fc70642896 100644 --- a/src/mscorlib/shared/System/IO/Path.cs +++ b/src/mscorlib/shared/System/IO/Path.cs @@ -368,12 +368,26 @@ namespace System.IO if (second.Length == 0) return new string(first); - if (IsPathRooted(second)) // will change to span version after the span pr is merged + if (IsPathRooted(second)) return new string(second); return CombineNoChecksInternal(first, second); } + private static string CombineNoChecks(string first, string second) + { + if (string.IsNullOrEmpty(first)) + return second; + + if (string.IsNullOrEmpty(second)) + return first; + + if (IsPathRooted(second.AsReadOnlySpan())) + return second; + + return CombineNoChecksInternal(first, second); + } + private static string CombineNoChecks(ReadOnlySpan first, ReadOnlySpan second, ReadOnlySpan third) { if (first.Length == 0) @@ -391,6 +405,23 @@ namespace System.IO return CombineNoChecksInternal(first, second, third); } + private static string CombineNoChecks(string first, string second, string third) + { + if (string.IsNullOrEmpty(first)) + return CombineNoChecks(second, third); + if (string.IsNullOrEmpty(second)) + return CombineNoChecks(first, third); + if (string.IsNullOrEmpty(third)) + return CombineNoChecks(first, second); + + if (IsPathRooted(third.AsReadOnlySpan())) + return third; + if (IsPathRooted(second.AsReadOnlySpan())) + return CombineNoChecks(second, third); + + return CombineNoChecksInternal(first, second, third); + } + private static string CombineNoChecks(ReadOnlySpan first, ReadOnlySpan second, ReadOnlySpan third, ReadOnlySpan fourth) { if (first.Length == 0) @@ -412,6 +443,27 @@ namespace System.IO return CombineNoChecksInternal(first, second, third, fourth); } + private static string CombineNoChecks(string first, string second, string third, string fourth) + { + if (string.IsNullOrEmpty(first)) + return CombineNoChecks(second, third, fourth); + if (string.IsNullOrEmpty(second)) + return CombineNoChecks(first, third, fourth); + if (string.IsNullOrEmpty(third)); + return CombineNoChecks(first, second, fourth); + if (string.IsNullOrEmpty(fourth)); + return CombineNoChecks(first, second, third); + + if (IsPathRooted(fourth.AsReadOnlySpan())) + return fourth; + if (IsPathRooted(third.AsReadOnlySpan())) + return CombineNoChecks(third, fourth); + if (IsPathRooted(second.AsReadOnlySpan())) + return CombineNoChecks(second, third, fourth); + + return CombineNoChecksInternal(first, second, third, fourth); + } + private unsafe static string CombineNoChecksInternal(ReadOnlySpan first, ReadOnlySpan second) { Debug.Assert(first.Length > 0 && second.Length > 0, "should have dealt with empty paths");