Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve WebUtility.HtmlEncode / UrlEncode performance (#103737)
* Improve WebUtility.HtmlEncode / UrlEncode performance - For HtmlEncode, vectorize IndexOfHtmlEncodingChars. Using SearchValues, we can efficiently search for the first ASCII encoding char or the first non-ASCII char, and only then fall back to a scalar loop. - For HtmlEncode, reduce branching by using a more efficient check to determine whether the ASCII characters need to be encoded. - For UrlEncode, rather than UTF8-encoding into a new byte[], %-encoding in-place in that, and then creating a string from that, we can use string.Create and just do all the encoding in that buffer. - For UrlEncode, use SearchValues to vectorize the search for the first non-safe char. Also move the check for ' ' to be inside the if for non-safe char. - For UrlEncode, use SearchValues to optimize the check for whether an individual character is part of the set (via Contains). - Simplify IsUrlSafeChar. Rather than multiple checks, one of which is a bitmap, just have a bitmap. - Remove some leading IsNullOrEmpty checks. Null/empty inputs should be rare, and they're now handled implicitly as part of the subsequent loops. * Update src/libraries/System.Private.CoreLib/src/System/Net/WebUtility.cs Co-authored-by: Miha Zupan <[email protected]> --------- Co-authored-by: Miha Zupan <[email protected]>
- Loading branch information