forked fromdotnet/runtime
- Notifications
You must be signed in to change notification settings - Fork1
Commitee9205d
Improve WebUtility.HtmlEncode / UrlEncode performance (dotnet#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.csCo-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>---------Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>1 parent25a0d84 commitee9205d
File tree
1 file changed
+137
-176
lines changed- src/libraries/System.Private.CoreLib/src/System/Net
1 file changed
+137
-176
lines changed0 commit comments
Comments
(0)