diff options
author | Ben Adams <thundercat@illyriad.co.uk> | 2018-04-12 22:08:04 +0100 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2018-04-12 14:08:04 -0700 |
commit | 6ac136e313826833b7fd32f0c8968297e8d7458e (patch) | |
tree | 9755b8020cbf5b356283e7604747849a5edcacf8 | |
parent | 153a4e5682b709d0c43ac12931e29ae7f9e8fbc8 (diff) | |
download | coreclr-6ac136e313826833b7fd32f0c8968297e8d7458e.tar.gz coreclr-6ac136e313826833b7fd32f0c8968297e8d7458e.tar.bz2 coreclr-6ac136e313826833b7fd32f0c8968297e8d7458e.zip |
Use string.IsNullOrEmpty to eliminate bounds check to first char (#17512)
-rw-r--r-- | src/mscorlib/shared/System/String.cs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/mscorlib/shared/System/String.cs b/src/mscorlib/shared/System/String.cs index 42d21ba068..9d230fe3dc 100644 --- a/src/mscorlib/shared/System/String.cs +++ b/src/mscorlib/shared/System/String.cs @@ -438,7 +438,13 @@ namespace System [NonVersionable] public static bool IsNullOrEmpty(string value) { - return (value == null || value.Length == 0); + // Using 0u >= (uint)value.Length rather than + // value.Length == 0 as it will elide the bounds check to + // the first char: value[0] if that is performed following the test + // for the same test cost. + // Ternary operator returning true/false prevents redundant asm generation: + // https://github.com/dotnet/coreclr/issues/914 + return (value == null || 0u >= (uint)value.Length) ? true : false; } public static bool IsNullOrWhiteSpace(string value) |