diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f31c88..77ec199 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 BigEndian/LittleEndian methods. - X10D: `Stream.GetHash<>` and `Stream.TryWriteHash<>` now throw ArgumentException in lieu of TypeInitializationException. +- X10D: `char.IsEmoji` no longer allocates for .NET 7. ### Removed diff --git a/X10D/src/Text/CharExtensions.cs b/X10D/src/Text/CharExtensions.cs index 2a3eef8..06ca0f7 100644 --- a/X10D/src/Text/CharExtensions.cs +++ b/X10D/src/Text/CharExtensions.cs @@ -18,7 +18,13 @@ public static class CharExtensions [MethodImpl(CompilerResources.MethodImplOptions)] public static bool IsEmoji(this char value) { - return value.ToString().IsEmoji(); +#if NET7_0_OR_GREATER + Span chars = stackalloc char[1]; + chars[0] = value; + return EmojiRegex.Value.IsMatch(chars); +#else + return EmojiRegex.Value.IsMatch(value.ToString()); +#endif } ///