From bacf76098efba66d66afe680d63f9758047dd38f Mon Sep 17 00:00:00 2001 From: Nick Craver Date: Tue, 3 Nov 2015 06:55:13 -0500 Subject: [PATCH] Performance improvements This adds additional performance improvements (namely string.Concat overloads) on top of #411. --- src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs | 2 +- src/Microsoft.AspNet.Http.Extensions/UriHelper.cs | 2 +- src/Microsoft.AspNet.Http/ResponseCookies.cs | 4 ++-- src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs b/src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs index 41757d29fb..87b22df243 100644 --- a/src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs +++ b/src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs @@ -100,7 +100,7 @@ namespace Microsoft.AspNet.Http string fragmentValue = uri.GetComponents(UriComponents.Fragment, UriFormat.UriEscaped); if (!string.IsNullOrEmpty(fragmentValue)) { - fragmentValue = $"#{fragmentValue}"; + fragmentValue = "#" + fragmentValue; } return new FragmentString(fragmentValue); } diff --git a/src/Microsoft.AspNet.Http.Extensions/UriHelper.cs b/src/Microsoft.AspNet.Http.Extensions/UriHelper.cs index e0d07b6a5f..28d89de253 100644 --- a/src/Microsoft.AspNet.Http.Extensions/UriHelper.cs +++ b/src/Microsoft.AspNet.Http.Extensions/UriHelper.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Http.Extensions FragmentString fragment = new FragmentString()) { string combinePath = (pathBase.HasValue || path.HasValue) ? (pathBase + path).ToString() : "/"; - return $"{combinePath}{query.ToString()}{fragment.ToString()}"; + return combinePath + query.ToString() + fragment.ToString(); } /// diff --git a/src/Microsoft.AspNet.Http/ResponseCookies.cs b/src/Microsoft.AspNet.Http/ResponseCookies.cs index ed76dec862..cd6b9c6ee9 100644 --- a/src/Microsoft.AspNet.Http/ResponseCookies.cs +++ b/src/Microsoft.AspNet.Http/ResponseCookies.cs @@ -80,7 +80,7 @@ namespace Microsoft.AspNet.Http.Internal /// public void Delete(string key) { - var encodedKeyPlusEquals = $"{UrlEncoder.Default.Encode(key)}="; + var encodedKeyPlusEquals = UrlEncoder.Default.Encode(key) + "="; Func predicate = (value, encKeyPlusEquals) => value.StartsWith(encKeyPlusEquals, StringComparison.OrdinalIgnoreCase); StringValues deleteCookies = $"{encodedKeyPlusEquals}; expires=Thu, 01-Jan-1970 00:00:00 GMT"; @@ -124,7 +124,7 @@ namespace Microsoft.AspNet.Http.Internal throw new ArgumentNullException(nameof(options)); } - var encodedKeyPlusEquals = $"{UrlEncoder.Default.Encode(key)}="; + var encodedKeyPlusEquals = UrlEncoder.Default.Encode(key) + "="; bool domainHasValue = !string.IsNullOrEmpty(options.Domain); bool pathHasValue = !string.IsNullOrEmpty(options.Path); diff --git a/src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs b/src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs index 036ed55795..6b0fd267ac 100644 --- a/src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs +++ b/src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs @@ -105,7 +105,7 @@ namespace Microsoft.AspNet.WebUtilities /// /// Parse a query string into its component key and value parts. /// - /// The raw query string value, with or without the leading '?'. + /// The raw query string value, with or without the leading '?'. /// A collection of parsed keys and values. public static Dictionary ParseQuery(string queryString) { @@ -123,7 +123,7 @@ namespace Microsoft.AspNet.WebUtilities /// /// Parse a query string into its component key and value parts. /// - /// The raw query string value, with or without the leading '?'. + /// The raw query string value, with or without the leading '?'. /// A collection of parsed keys and values, null if there are no entries. public static Dictionary ParseNullableQuery(string queryString) { @@ -135,7 +135,7 @@ namespace Microsoft.AspNet.WebUtilities } int scanIndex = 0; - if (!string.IsNullOrEmpty(queryString) && queryString[0] == '?') + if (queryString[0] == '?') { scanIndex = 1; }