From 2f2ac00387affb7570c69513298aa8bcf8733114 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sat, 17 Jun 2017 21:40:38 -0400 Subject: [PATCH] Further improve perf of Char.IsWhiteSpace (dotnet/coreclr#12353) IsWhiteSpaceLatin1 is not being inlined. By changing a range check done with two comparison operations to instead be done with a subtraction and a single comparison, the code is shortened to not only be less expensive but also then get inlined into IsWhiteSpace and then further into String.IsNullOrWhiteSpace. The net result is a measurable throughput improvement for IsNullOrWhiteSpace. Commit migrated from https://github.com/dotnet/coreclr/commit/7c197b63914af560d467e8a95c04177495f160d9 --- src/coreclr/src/mscorlib/shared/System/Char.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/mscorlib/shared/System/Char.cs b/src/coreclr/src/mscorlib/shared/System/Char.cs index a5a3f7b..bce2714 100644 --- a/src/coreclr/src/mscorlib/shared/System/Char.cs +++ b/src/coreclr/src/mscorlib/shared/System/Char.cs @@ -274,7 +274,11 @@ namespace System // U+000d = CARRIAGE RETURN // U+0085 = NEXT LINE // U+00a0 = NO-BREAK SPACE - return c == ' ' || (c >= '\x0009' && c <= '\x000d') || c == '\x00a0' || c == '\x0085'; + return + c == ' ' || + (uint)(c - '\x0009') <= ('\x000d' - '\x0009') || // (c >= '\x0009' && c <= '\x000d') + c == '\x00a0' || + c == '\x0085'; } /*===============================ISWHITESPACE=================================== -- 2.7.4