diff --git a/src/Polyfill/OperatingSystemPolyfill.cs b/src/Polyfill/OperatingSystemPolyfill.cs index f02477d3..71a34dbf 100644 --- a/src/Polyfill/OperatingSystemPolyfill.cs +++ b/src/Polyfill/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -86,6 +87,7 @@ public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = /// Indicates whether the current application is running on the specified platform. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isosplatform?view=net-11.0 + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); diff --git a/src/Split/net10.0/ConsolePolyfill.cs b/src/Split/net10.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net10.0/ConsolePolyfill.cs +++ b/src/Split/net10.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net11.0/ConsolePolyfill.cs b/src/Split/net11.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net11.0/ConsolePolyfill.cs +++ b/src/Split/net11.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net461/ConsolePolyfill.cs b/src/Split/net461/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net461/ConsolePolyfill.cs +++ b/src/Split/net461/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net461/ConvertPolyfill.cs b/src/Split/net461/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/net461/ConvertPolyfill.cs +++ b/src/Split/net461/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net461/DateTimeOffsetPolyfill.cs b/src/Split/net461/DateTimeOffsetPolyfill.cs index 6837790e..7bb9a5ad 100644 --- a/src/Split/net461/DateTimeOffsetPolyfill.cs +++ b/src/Split/net461/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,32 +31,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net461/DateTimePolyfill.cs b/src/Split/net461/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/net461/DateTimePolyfill.cs +++ b/src/Split/net461/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net461/DelegatePolyfill.cs b/src/Split/net461/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net461/DelegatePolyfill.cs +++ b/src/Split/net461/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net461/FilePolyfill.cs b/src/Split/net461/FilePolyfill.cs index c6112e74..66cb81a1 100644 --- a/src/Split/net461/FilePolyfill.cs +++ b/src/Split/net461/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net461/GuidPolyfill.cs b/src/Split/net461/GuidPolyfill.cs index 2bd53673..bc6b9129 100644 --- a/src/Split/net461/GuidPolyfill.cs +++ b/src/Split/net461/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, out Guid result) => Guid.TryParseExact(input.ToString(), format.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net461/KeyValuePair.cs b/src/Split/net461/KeyValuePair.cs index 7e5d5895..e94cbbf2 100644 --- a/src/Split/net461/KeyValuePair.cs +++ b/src/Split/net461/KeyValuePair.cs @@ -4,6 +4,7 @@ namespace System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; [ExcludeFromCodeCoverage] [DebuggerNonUserCode] #if PolyUseEmbeddedAttribute @@ -17,6 +18,7 @@ static class KeyValuePair /// /// Creates a new key/value pair instance using provided values. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static KeyValuePair Create(TKey key, TValue value) => new(key, value); } diff --git a/src/Split/net461/Lock.cs b/src/Split/net461/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net461/Lock.cs +++ b/src/Split/net461/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net461/Numbers/BytePolyfill.cs b/src/Split/net461/Numbers/BytePolyfill.cs index ef3f744e..0ea017af 100644 --- a/src/Split/net461/Numbers/BytePolyfill.cs +++ b/src/Split/net461/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,37 +13,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out byte result) => byte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif diff --git a/src/Split/net461/Numbers/DoublePolyfill.cs b/src/Split/net461/Numbers/DoublePolyfill.cs index ba5333f6..d903ddfe 100644 --- a/src/Split/net461/Numbers/DoublePolyfill.cs +++ b/src/Split/net461/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out double result) => double.TryParse(s.ToString(), out result); /// /// Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/net461/Numbers/Int16Polyfill.cs b/src/Split/net461/Numbers/Int16Polyfill.cs index 5eb1b384..960cf68c 100644 --- a/src/Split/net461/Numbers/Int16Polyfill.cs +++ b/src/Split/net461/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out short result) => short.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net461/Numbers/Int32Polyfill.cs b/src/Split/net461/Numbers/Int32Polyfill.cs index 549ff189..2920eae4 100644 --- a/src/Split/net461/Numbers/Int32Polyfill.cs +++ b/src/Split/net461/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out int result) => int.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net461/Numbers/Int64Polyfill.cs b/src/Split/net461/Numbers/Int64Polyfill.cs index bd33ce0e..0b7b1b10 100644 --- a/src/Split/net461/Numbers/Int64Polyfill.cs +++ b/src/Split/net461/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out long result) => long.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net461/Numbers/SBytePolyfill.cs b/src/Split/net461/Numbers/SBytePolyfill.cs index 97411565..890452b1 100644 --- a/src/Split/net461/Numbers/SBytePolyfill.cs +++ b/src/Split/net461/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out sbyte result) => sbyte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net461/Numbers/UInt16Polyfill.cs b/src/Split/net461/Numbers/UInt16Polyfill.cs index 34f39f97..ed095880 100644 --- a/src/Split/net461/Numbers/UInt16Polyfill.cs +++ b/src/Split/net461/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ushort result) => ushort.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net461/Numbers/UInt32Polyfill.cs b/src/Split/net461/Numbers/UInt32Polyfill.cs index 859149be..e11b65c9 100644 --- a/src/Split/net461/Numbers/UInt32Polyfill.cs +++ b/src/Split/net461/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out uint result) => uint.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net461/Numbers/UInt64Polyfill.cs b/src/Split/net461/Numbers/UInt64Polyfill.cs index c14bb347..10122d2b 100644 --- a/src/Split/net461/Numbers/UInt64Polyfill.cs +++ b/src/Split/net461/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ulong result) => ulong.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net461/OperatingSystemPolyfill.cs b/src/Split/net461/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/net461/OperatingSystemPolyfill.cs +++ b/src/Split/net461/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/net461/PathPolyfill.cs b/src/Split/net461/PathPolyfill.cs index fb4329ac..fc8009da 100644 --- a/src/Split/net461/PathPolyfill.cs +++ b/src/Split/net461/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,41 +12,49 @@ static partial class Polyfill /// /// Returns the directory information for the specified path represented by a character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetDirectoryName(ReadOnlySpan path) => Path.GetDirectoryName(path.ToString()).AsSpan(); /// /// Returns the file name and extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileName(ReadOnlySpan path) => Path.GetFileName(path.ToString()).AsSpan(); /// /// Returns the file name without the extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) => Path.GetFileNameWithoutExtension(path.ToString()).AsSpan(); /// /// Determines whether the path represented by the specified character span includes a file name extension. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasExtension(ReadOnlySpan path) => Path.HasExtension(path.ToString()); /// /// Returns the extension of the given path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetExtension(ReadOnlySpan path) => Path.GetExtension(path.ToString()).AsSpan(); /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/net462/ConsolePolyfill.cs b/src/Split/net462/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net462/ConsolePolyfill.cs +++ b/src/Split/net462/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net462/ConvertPolyfill.cs b/src/Split/net462/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/net462/ConvertPolyfill.cs +++ b/src/Split/net462/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net462/DateTimeOffsetPolyfill.cs b/src/Split/net462/DateTimeOffsetPolyfill.cs index 6837790e..7bb9a5ad 100644 --- a/src/Split/net462/DateTimeOffsetPolyfill.cs +++ b/src/Split/net462/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,32 +31,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net462/DateTimePolyfill.cs b/src/Split/net462/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/net462/DateTimePolyfill.cs +++ b/src/Split/net462/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net462/DelegatePolyfill.cs b/src/Split/net462/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net462/DelegatePolyfill.cs +++ b/src/Split/net462/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net462/FilePolyfill.cs b/src/Split/net462/FilePolyfill.cs index c6112e74..66cb81a1 100644 --- a/src/Split/net462/FilePolyfill.cs +++ b/src/Split/net462/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net462/GuidPolyfill.cs b/src/Split/net462/GuidPolyfill.cs index 2bd53673..bc6b9129 100644 --- a/src/Split/net462/GuidPolyfill.cs +++ b/src/Split/net462/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, out Guid result) => Guid.TryParseExact(input.ToString(), format.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net462/KeyValuePair.cs b/src/Split/net462/KeyValuePair.cs index 7e5d5895..e94cbbf2 100644 --- a/src/Split/net462/KeyValuePair.cs +++ b/src/Split/net462/KeyValuePair.cs @@ -4,6 +4,7 @@ namespace System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; [ExcludeFromCodeCoverage] [DebuggerNonUserCode] #if PolyUseEmbeddedAttribute @@ -17,6 +18,7 @@ static class KeyValuePair /// /// Creates a new key/value pair instance using provided values. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static KeyValuePair Create(TKey key, TValue value) => new(key, value); } diff --git a/src/Split/net462/Lock.cs b/src/Split/net462/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net462/Lock.cs +++ b/src/Split/net462/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net462/Numbers/BytePolyfill.cs b/src/Split/net462/Numbers/BytePolyfill.cs index ef3f744e..0ea017af 100644 --- a/src/Split/net462/Numbers/BytePolyfill.cs +++ b/src/Split/net462/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,37 +13,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out byte result) => byte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif diff --git a/src/Split/net462/Numbers/DoublePolyfill.cs b/src/Split/net462/Numbers/DoublePolyfill.cs index ba5333f6..d903ddfe 100644 --- a/src/Split/net462/Numbers/DoublePolyfill.cs +++ b/src/Split/net462/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out double result) => double.TryParse(s.ToString(), out result); /// /// Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/net462/Numbers/Int16Polyfill.cs b/src/Split/net462/Numbers/Int16Polyfill.cs index 5eb1b384..960cf68c 100644 --- a/src/Split/net462/Numbers/Int16Polyfill.cs +++ b/src/Split/net462/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out short result) => short.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net462/Numbers/Int32Polyfill.cs b/src/Split/net462/Numbers/Int32Polyfill.cs index 549ff189..2920eae4 100644 --- a/src/Split/net462/Numbers/Int32Polyfill.cs +++ b/src/Split/net462/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out int result) => int.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net462/Numbers/Int64Polyfill.cs b/src/Split/net462/Numbers/Int64Polyfill.cs index bd33ce0e..0b7b1b10 100644 --- a/src/Split/net462/Numbers/Int64Polyfill.cs +++ b/src/Split/net462/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out long result) => long.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net462/Numbers/SBytePolyfill.cs b/src/Split/net462/Numbers/SBytePolyfill.cs index 97411565..890452b1 100644 --- a/src/Split/net462/Numbers/SBytePolyfill.cs +++ b/src/Split/net462/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out sbyte result) => sbyte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net462/Numbers/UInt16Polyfill.cs b/src/Split/net462/Numbers/UInt16Polyfill.cs index 34f39f97..ed095880 100644 --- a/src/Split/net462/Numbers/UInt16Polyfill.cs +++ b/src/Split/net462/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ushort result) => ushort.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net462/Numbers/UInt32Polyfill.cs b/src/Split/net462/Numbers/UInt32Polyfill.cs index 859149be..e11b65c9 100644 --- a/src/Split/net462/Numbers/UInt32Polyfill.cs +++ b/src/Split/net462/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out uint result) => uint.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net462/Numbers/UInt64Polyfill.cs b/src/Split/net462/Numbers/UInt64Polyfill.cs index c14bb347..10122d2b 100644 --- a/src/Split/net462/Numbers/UInt64Polyfill.cs +++ b/src/Split/net462/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ulong result) => ulong.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net462/OperatingSystemPolyfill.cs b/src/Split/net462/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/net462/OperatingSystemPolyfill.cs +++ b/src/Split/net462/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/net462/PathPolyfill.cs b/src/Split/net462/PathPolyfill.cs index fb4329ac..fc8009da 100644 --- a/src/Split/net462/PathPolyfill.cs +++ b/src/Split/net462/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,41 +12,49 @@ static partial class Polyfill /// /// Returns the directory information for the specified path represented by a character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetDirectoryName(ReadOnlySpan path) => Path.GetDirectoryName(path.ToString()).AsSpan(); /// /// Returns the file name and extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileName(ReadOnlySpan path) => Path.GetFileName(path.ToString()).AsSpan(); /// /// Returns the file name without the extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) => Path.GetFileNameWithoutExtension(path.ToString()).AsSpan(); /// /// Determines whether the path represented by the specified character span includes a file name extension. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasExtension(ReadOnlySpan path) => Path.HasExtension(path.ToString()); /// /// Returns the extension of the given path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetExtension(ReadOnlySpan path) => Path.GetExtension(path.ToString()).AsSpan(); /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/net47/ConsolePolyfill.cs b/src/Split/net47/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net47/ConsolePolyfill.cs +++ b/src/Split/net47/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net47/ConvertPolyfill.cs b/src/Split/net47/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/net47/ConvertPolyfill.cs +++ b/src/Split/net47/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net47/DateTimeOffsetPolyfill.cs b/src/Split/net47/DateTimeOffsetPolyfill.cs index 6837790e..7bb9a5ad 100644 --- a/src/Split/net47/DateTimeOffsetPolyfill.cs +++ b/src/Split/net47/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,32 +31,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net47/DateTimePolyfill.cs b/src/Split/net47/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/net47/DateTimePolyfill.cs +++ b/src/Split/net47/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net47/DelegatePolyfill.cs b/src/Split/net47/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net47/DelegatePolyfill.cs +++ b/src/Split/net47/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net47/FilePolyfill.cs b/src/Split/net47/FilePolyfill.cs index c6112e74..66cb81a1 100644 --- a/src/Split/net47/FilePolyfill.cs +++ b/src/Split/net47/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net47/GuidPolyfill.cs b/src/Split/net47/GuidPolyfill.cs index 2bd53673..bc6b9129 100644 --- a/src/Split/net47/GuidPolyfill.cs +++ b/src/Split/net47/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, out Guid result) => Guid.TryParseExact(input.ToString(), format.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net47/KeyValuePair.cs b/src/Split/net47/KeyValuePair.cs index 7e5d5895..e94cbbf2 100644 --- a/src/Split/net47/KeyValuePair.cs +++ b/src/Split/net47/KeyValuePair.cs @@ -4,6 +4,7 @@ namespace System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; [ExcludeFromCodeCoverage] [DebuggerNonUserCode] #if PolyUseEmbeddedAttribute @@ -17,6 +18,7 @@ static class KeyValuePair /// /// Creates a new key/value pair instance using provided values. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static KeyValuePair Create(TKey key, TValue value) => new(key, value); } diff --git a/src/Split/net47/Lock.cs b/src/Split/net47/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net47/Lock.cs +++ b/src/Split/net47/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net47/Numbers/BytePolyfill.cs b/src/Split/net47/Numbers/BytePolyfill.cs index ef3f744e..0ea017af 100644 --- a/src/Split/net47/Numbers/BytePolyfill.cs +++ b/src/Split/net47/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,37 +13,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out byte result) => byte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif diff --git a/src/Split/net47/Numbers/DoublePolyfill.cs b/src/Split/net47/Numbers/DoublePolyfill.cs index ba5333f6..d903ddfe 100644 --- a/src/Split/net47/Numbers/DoublePolyfill.cs +++ b/src/Split/net47/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out double result) => double.TryParse(s.ToString(), out result); /// /// Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/net47/Numbers/Int16Polyfill.cs b/src/Split/net47/Numbers/Int16Polyfill.cs index 5eb1b384..960cf68c 100644 --- a/src/Split/net47/Numbers/Int16Polyfill.cs +++ b/src/Split/net47/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out short result) => short.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net47/Numbers/Int32Polyfill.cs b/src/Split/net47/Numbers/Int32Polyfill.cs index 549ff189..2920eae4 100644 --- a/src/Split/net47/Numbers/Int32Polyfill.cs +++ b/src/Split/net47/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out int result) => int.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net47/Numbers/Int64Polyfill.cs b/src/Split/net47/Numbers/Int64Polyfill.cs index bd33ce0e..0b7b1b10 100644 --- a/src/Split/net47/Numbers/Int64Polyfill.cs +++ b/src/Split/net47/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out long result) => long.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net47/Numbers/SBytePolyfill.cs b/src/Split/net47/Numbers/SBytePolyfill.cs index 97411565..890452b1 100644 --- a/src/Split/net47/Numbers/SBytePolyfill.cs +++ b/src/Split/net47/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out sbyte result) => sbyte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net47/Numbers/UInt16Polyfill.cs b/src/Split/net47/Numbers/UInt16Polyfill.cs index 34f39f97..ed095880 100644 --- a/src/Split/net47/Numbers/UInt16Polyfill.cs +++ b/src/Split/net47/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ushort result) => ushort.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net47/Numbers/UInt32Polyfill.cs b/src/Split/net47/Numbers/UInt32Polyfill.cs index 859149be..e11b65c9 100644 --- a/src/Split/net47/Numbers/UInt32Polyfill.cs +++ b/src/Split/net47/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out uint result) => uint.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net47/Numbers/UInt64Polyfill.cs b/src/Split/net47/Numbers/UInt64Polyfill.cs index c14bb347..10122d2b 100644 --- a/src/Split/net47/Numbers/UInt64Polyfill.cs +++ b/src/Split/net47/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ulong result) => ulong.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net47/OperatingSystemPolyfill.cs b/src/Split/net47/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/net47/OperatingSystemPolyfill.cs +++ b/src/Split/net47/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/net47/PathPolyfill.cs b/src/Split/net47/PathPolyfill.cs index fb4329ac..fc8009da 100644 --- a/src/Split/net47/PathPolyfill.cs +++ b/src/Split/net47/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,41 +12,49 @@ static partial class Polyfill /// /// Returns the directory information for the specified path represented by a character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetDirectoryName(ReadOnlySpan path) => Path.GetDirectoryName(path.ToString()).AsSpan(); /// /// Returns the file name and extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileName(ReadOnlySpan path) => Path.GetFileName(path.ToString()).AsSpan(); /// /// Returns the file name without the extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) => Path.GetFileNameWithoutExtension(path.ToString()).AsSpan(); /// /// Determines whether the path represented by the specified character span includes a file name extension. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasExtension(ReadOnlySpan path) => Path.HasExtension(path.ToString()); /// /// Returns the extension of the given path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetExtension(ReadOnlySpan path) => Path.GetExtension(path.ToString()).AsSpan(); /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/net471/ConsolePolyfill.cs b/src/Split/net471/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net471/ConsolePolyfill.cs +++ b/src/Split/net471/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net471/ConvertPolyfill.cs b/src/Split/net471/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/net471/ConvertPolyfill.cs +++ b/src/Split/net471/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net471/DateTimeOffsetPolyfill.cs b/src/Split/net471/DateTimeOffsetPolyfill.cs index 6837790e..7bb9a5ad 100644 --- a/src/Split/net471/DateTimeOffsetPolyfill.cs +++ b/src/Split/net471/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,32 +31,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net471/DateTimePolyfill.cs b/src/Split/net471/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/net471/DateTimePolyfill.cs +++ b/src/Split/net471/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net471/DelegatePolyfill.cs b/src/Split/net471/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net471/DelegatePolyfill.cs +++ b/src/Split/net471/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net471/FilePolyfill.cs b/src/Split/net471/FilePolyfill.cs index c6112e74..66cb81a1 100644 --- a/src/Split/net471/FilePolyfill.cs +++ b/src/Split/net471/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net471/GuidPolyfill.cs b/src/Split/net471/GuidPolyfill.cs index 2bd53673..bc6b9129 100644 --- a/src/Split/net471/GuidPolyfill.cs +++ b/src/Split/net471/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, out Guid result) => Guid.TryParseExact(input.ToString(), format.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net471/KeyValuePair.cs b/src/Split/net471/KeyValuePair.cs index 7e5d5895..e94cbbf2 100644 --- a/src/Split/net471/KeyValuePair.cs +++ b/src/Split/net471/KeyValuePair.cs @@ -4,6 +4,7 @@ namespace System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; [ExcludeFromCodeCoverage] [DebuggerNonUserCode] #if PolyUseEmbeddedAttribute @@ -17,6 +18,7 @@ static class KeyValuePair /// /// Creates a new key/value pair instance using provided values. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static KeyValuePair Create(TKey key, TValue value) => new(key, value); } diff --git a/src/Split/net471/Lock.cs b/src/Split/net471/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net471/Lock.cs +++ b/src/Split/net471/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net471/Numbers/BytePolyfill.cs b/src/Split/net471/Numbers/BytePolyfill.cs index ef3f744e..0ea017af 100644 --- a/src/Split/net471/Numbers/BytePolyfill.cs +++ b/src/Split/net471/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,37 +13,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out byte result) => byte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif diff --git a/src/Split/net471/Numbers/DoublePolyfill.cs b/src/Split/net471/Numbers/DoublePolyfill.cs index ba5333f6..d903ddfe 100644 --- a/src/Split/net471/Numbers/DoublePolyfill.cs +++ b/src/Split/net471/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out double result) => double.TryParse(s.ToString(), out result); /// /// Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/net471/Numbers/Int16Polyfill.cs b/src/Split/net471/Numbers/Int16Polyfill.cs index 5eb1b384..960cf68c 100644 --- a/src/Split/net471/Numbers/Int16Polyfill.cs +++ b/src/Split/net471/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out short result) => short.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net471/Numbers/Int32Polyfill.cs b/src/Split/net471/Numbers/Int32Polyfill.cs index 549ff189..2920eae4 100644 --- a/src/Split/net471/Numbers/Int32Polyfill.cs +++ b/src/Split/net471/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out int result) => int.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net471/Numbers/Int64Polyfill.cs b/src/Split/net471/Numbers/Int64Polyfill.cs index bd33ce0e..0b7b1b10 100644 --- a/src/Split/net471/Numbers/Int64Polyfill.cs +++ b/src/Split/net471/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out long result) => long.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net471/Numbers/SBytePolyfill.cs b/src/Split/net471/Numbers/SBytePolyfill.cs index 97411565..890452b1 100644 --- a/src/Split/net471/Numbers/SBytePolyfill.cs +++ b/src/Split/net471/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out sbyte result) => sbyte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net471/Numbers/UInt16Polyfill.cs b/src/Split/net471/Numbers/UInt16Polyfill.cs index 34f39f97..ed095880 100644 --- a/src/Split/net471/Numbers/UInt16Polyfill.cs +++ b/src/Split/net471/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ushort result) => ushort.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net471/Numbers/UInt32Polyfill.cs b/src/Split/net471/Numbers/UInt32Polyfill.cs index 859149be..e11b65c9 100644 --- a/src/Split/net471/Numbers/UInt32Polyfill.cs +++ b/src/Split/net471/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out uint result) => uint.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net471/Numbers/UInt64Polyfill.cs b/src/Split/net471/Numbers/UInt64Polyfill.cs index c14bb347..10122d2b 100644 --- a/src/Split/net471/Numbers/UInt64Polyfill.cs +++ b/src/Split/net471/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ulong result) => ulong.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net471/OperatingSystemPolyfill.cs b/src/Split/net471/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/net471/OperatingSystemPolyfill.cs +++ b/src/Split/net471/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/net471/PathPolyfill.cs b/src/Split/net471/PathPolyfill.cs index fb4329ac..fc8009da 100644 --- a/src/Split/net471/PathPolyfill.cs +++ b/src/Split/net471/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,41 +12,49 @@ static partial class Polyfill /// /// Returns the directory information for the specified path represented by a character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetDirectoryName(ReadOnlySpan path) => Path.GetDirectoryName(path.ToString()).AsSpan(); /// /// Returns the file name and extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileName(ReadOnlySpan path) => Path.GetFileName(path.ToString()).AsSpan(); /// /// Returns the file name without the extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) => Path.GetFileNameWithoutExtension(path.ToString()).AsSpan(); /// /// Determines whether the path represented by the specified character span includes a file name extension. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasExtension(ReadOnlySpan path) => Path.HasExtension(path.ToString()); /// /// Returns the extension of the given path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetExtension(ReadOnlySpan path) => Path.GetExtension(path.ToString()).AsSpan(); /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/net472/ConsolePolyfill.cs b/src/Split/net472/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net472/ConsolePolyfill.cs +++ b/src/Split/net472/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net472/ConvertPolyfill.cs b/src/Split/net472/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/net472/ConvertPolyfill.cs +++ b/src/Split/net472/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net472/DateTimeOffsetPolyfill.cs b/src/Split/net472/DateTimeOffsetPolyfill.cs index 6837790e..7bb9a5ad 100644 --- a/src/Split/net472/DateTimeOffsetPolyfill.cs +++ b/src/Split/net472/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,32 +31,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net472/DateTimePolyfill.cs b/src/Split/net472/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/net472/DateTimePolyfill.cs +++ b/src/Split/net472/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net472/DelegatePolyfill.cs b/src/Split/net472/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net472/DelegatePolyfill.cs +++ b/src/Split/net472/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net472/FilePolyfill.cs b/src/Split/net472/FilePolyfill.cs index c6112e74..66cb81a1 100644 --- a/src/Split/net472/FilePolyfill.cs +++ b/src/Split/net472/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net472/GuidPolyfill.cs b/src/Split/net472/GuidPolyfill.cs index 2bd53673..bc6b9129 100644 --- a/src/Split/net472/GuidPolyfill.cs +++ b/src/Split/net472/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, out Guid result) => Guid.TryParseExact(input.ToString(), format.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net472/KeyValuePair.cs b/src/Split/net472/KeyValuePair.cs index 7e5d5895..e94cbbf2 100644 --- a/src/Split/net472/KeyValuePair.cs +++ b/src/Split/net472/KeyValuePair.cs @@ -4,6 +4,7 @@ namespace System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; [ExcludeFromCodeCoverage] [DebuggerNonUserCode] #if PolyUseEmbeddedAttribute @@ -17,6 +18,7 @@ static class KeyValuePair /// /// Creates a new key/value pair instance using provided values. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static KeyValuePair Create(TKey key, TValue value) => new(key, value); } diff --git a/src/Split/net472/Lock.cs b/src/Split/net472/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net472/Lock.cs +++ b/src/Split/net472/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net472/Numbers/BytePolyfill.cs b/src/Split/net472/Numbers/BytePolyfill.cs index ef3f744e..0ea017af 100644 --- a/src/Split/net472/Numbers/BytePolyfill.cs +++ b/src/Split/net472/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,37 +13,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out byte result) => byte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif diff --git a/src/Split/net472/Numbers/DoublePolyfill.cs b/src/Split/net472/Numbers/DoublePolyfill.cs index ba5333f6..d903ddfe 100644 --- a/src/Split/net472/Numbers/DoublePolyfill.cs +++ b/src/Split/net472/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out double result) => double.TryParse(s.ToString(), out result); /// /// Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/net472/Numbers/Int16Polyfill.cs b/src/Split/net472/Numbers/Int16Polyfill.cs index 5eb1b384..960cf68c 100644 --- a/src/Split/net472/Numbers/Int16Polyfill.cs +++ b/src/Split/net472/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out short result) => short.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net472/Numbers/Int32Polyfill.cs b/src/Split/net472/Numbers/Int32Polyfill.cs index 549ff189..2920eae4 100644 --- a/src/Split/net472/Numbers/Int32Polyfill.cs +++ b/src/Split/net472/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out int result) => int.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net472/Numbers/Int64Polyfill.cs b/src/Split/net472/Numbers/Int64Polyfill.cs index bd33ce0e..0b7b1b10 100644 --- a/src/Split/net472/Numbers/Int64Polyfill.cs +++ b/src/Split/net472/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out long result) => long.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net472/Numbers/SBytePolyfill.cs b/src/Split/net472/Numbers/SBytePolyfill.cs index 97411565..890452b1 100644 --- a/src/Split/net472/Numbers/SBytePolyfill.cs +++ b/src/Split/net472/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out sbyte result) => sbyte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net472/Numbers/UInt16Polyfill.cs b/src/Split/net472/Numbers/UInt16Polyfill.cs index 34f39f97..ed095880 100644 --- a/src/Split/net472/Numbers/UInt16Polyfill.cs +++ b/src/Split/net472/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ushort result) => ushort.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net472/Numbers/UInt32Polyfill.cs b/src/Split/net472/Numbers/UInt32Polyfill.cs index 859149be..e11b65c9 100644 --- a/src/Split/net472/Numbers/UInt32Polyfill.cs +++ b/src/Split/net472/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out uint result) => uint.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net472/Numbers/UInt64Polyfill.cs b/src/Split/net472/Numbers/UInt64Polyfill.cs index c14bb347..10122d2b 100644 --- a/src/Split/net472/Numbers/UInt64Polyfill.cs +++ b/src/Split/net472/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ulong result) => ulong.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net472/OperatingSystemPolyfill.cs b/src/Split/net472/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/net472/OperatingSystemPolyfill.cs +++ b/src/Split/net472/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/net472/PathPolyfill.cs b/src/Split/net472/PathPolyfill.cs index fb4329ac..fc8009da 100644 --- a/src/Split/net472/PathPolyfill.cs +++ b/src/Split/net472/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,41 +12,49 @@ static partial class Polyfill /// /// Returns the directory information for the specified path represented by a character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetDirectoryName(ReadOnlySpan path) => Path.GetDirectoryName(path.ToString()).AsSpan(); /// /// Returns the file name and extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileName(ReadOnlySpan path) => Path.GetFileName(path.ToString()).AsSpan(); /// /// Returns the file name without the extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) => Path.GetFileNameWithoutExtension(path.ToString()).AsSpan(); /// /// Determines whether the path represented by the specified character span includes a file name extension. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasExtension(ReadOnlySpan path) => Path.HasExtension(path.ToString()); /// /// Returns the extension of the given path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetExtension(ReadOnlySpan path) => Path.GetExtension(path.ToString()).AsSpan(); /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/net48/ConsolePolyfill.cs b/src/Split/net48/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net48/ConsolePolyfill.cs +++ b/src/Split/net48/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net48/ConvertPolyfill.cs b/src/Split/net48/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/net48/ConvertPolyfill.cs +++ b/src/Split/net48/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net48/DateTimeOffsetPolyfill.cs b/src/Split/net48/DateTimeOffsetPolyfill.cs index 6837790e..7bb9a5ad 100644 --- a/src/Split/net48/DateTimeOffsetPolyfill.cs +++ b/src/Split/net48/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,32 +31,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net48/DateTimePolyfill.cs b/src/Split/net48/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/net48/DateTimePolyfill.cs +++ b/src/Split/net48/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net48/DelegatePolyfill.cs b/src/Split/net48/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net48/DelegatePolyfill.cs +++ b/src/Split/net48/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net48/FilePolyfill.cs b/src/Split/net48/FilePolyfill.cs index c6112e74..66cb81a1 100644 --- a/src/Split/net48/FilePolyfill.cs +++ b/src/Split/net48/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net48/GuidPolyfill.cs b/src/Split/net48/GuidPolyfill.cs index 2bd53673..bc6b9129 100644 --- a/src/Split/net48/GuidPolyfill.cs +++ b/src/Split/net48/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, out Guid result) => Guid.TryParseExact(input.ToString(), format.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net48/KeyValuePair.cs b/src/Split/net48/KeyValuePair.cs index 7e5d5895..e94cbbf2 100644 --- a/src/Split/net48/KeyValuePair.cs +++ b/src/Split/net48/KeyValuePair.cs @@ -4,6 +4,7 @@ namespace System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; [ExcludeFromCodeCoverage] [DebuggerNonUserCode] #if PolyUseEmbeddedAttribute @@ -17,6 +18,7 @@ static class KeyValuePair /// /// Creates a new key/value pair instance using provided values. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static KeyValuePair Create(TKey key, TValue value) => new(key, value); } diff --git a/src/Split/net48/Lock.cs b/src/Split/net48/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net48/Lock.cs +++ b/src/Split/net48/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net48/Numbers/BytePolyfill.cs b/src/Split/net48/Numbers/BytePolyfill.cs index ef3f744e..0ea017af 100644 --- a/src/Split/net48/Numbers/BytePolyfill.cs +++ b/src/Split/net48/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,37 +13,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out byte result) => byte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif diff --git a/src/Split/net48/Numbers/DoublePolyfill.cs b/src/Split/net48/Numbers/DoublePolyfill.cs index ba5333f6..d903ddfe 100644 --- a/src/Split/net48/Numbers/DoublePolyfill.cs +++ b/src/Split/net48/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out double result) => double.TryParse(s.ToString(), out result); /// /// Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/net48/Numbers/Int16Polyfill.cs b/src/Split/net48/Numbers/Int16Polyfill.cs index 5eb1b384..960cf68c 100644 --- a/src/Split/net48/Numbers/Int16Polyfill.cs +++ b/src/Split/net48/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out short result) => short.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net48/Numbers/Int32Polyfill.cs b/src/Split/net48/Numbers/Int32Polyfill.cs index 549ff189..2920eae4 100644 --- a/src/Split/net48/Numbers/Int32Polyfill.cs +++ b/src/Split/net48/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out int result) => int.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net48/Numbers/Int64Polyfill.cs b/src/Split/net48/Numbers/Int64Polyfill.cs index bd33ce0e..0b7b1b10 100644 --- a/src/Split/net48/Numbers/Int64Polyfill.cs +++ b/src/Split/net48/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out long result) => long.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net48/Numbers/SBytePolyfill.cs b/src/Split/net48/Numbers/SBytePolyfill.cs index 97411565..890452b1 100644 --- a/src/Split/net48/Numbers/SBytePolyfill.cs +++ b/src/Split/net48/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out sbyte result) => sbyte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net48/Numbers/UInt16Polyfill.cs b/src/Split/net48/Numbers/UInt16Polyfill.cs index 34f39f97..ed095880 100644 --- a/src/Split/net48/Numbers/UInt16Polyfill.cs +++ b/src/Split/net48/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ushort result) => ushort.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net48/Numbers/UInt32Polyfill.cs b/src/Split/net48/Numbers/UInt32Polyfill.cs index 859149be..e11b65c9 100644 --- a/src/Split/net48/Numbers/UInt32Polyfill.cs +++ b/src/Split/net48/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out uint result) => uint.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net48/Numbers/UInt64Polyfill.cs b/src/Split/net48/Numbers/UInt64Polyfill.cs index c14bb347..10122d2b 100644 --- a/src/Split/net48/Numbers/UInt64Polyfill.cs +++ b/src/Split/net48/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ulong result) => ulong.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net48/OperatingSystemPolyfill.cs b/src/Split/net48/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/net48/OperatingSystemPolyfill.cs +++ b/src/Split/net48/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/net48/PathPolyfill.cs b/src/Split/net48/PathPolyfill.cs index fb4329ac..fc8009da 100644 --- a/src/Split/net48/PathPolyfill.cs +++ b/src/Split/net48/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,41 +12,49 @@ static partial class Polyfill /// /// Returns the directory information for the specified path represented by a character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetDirectoryName(ReadOnlySpan path) => Path.GetDirectoryName(path.ToString()).AsSpan(); /// /// Returns the file name and extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileName(ReadOnlySpan path) => Path.GetFileName(path.ToString()).AsSpan(); /// /// Returns the file name without the extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) => Path.GetFileNameWithoutExtension(path.ToString()).AsSpan(); /// /// Determines whether the path represented by the specified character span includes a file name extension. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasExtension(ReadOnlySpan path) => Path.HasExtension(path.ToString()); /// /// Returns the extension of the given path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetExtension(ReadOnlySpan path) => Path.GetExtension(path.ToString()).AsSpan(); /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/net481/ConsolePolyfill.cs b/src/Split/net481/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net481/ConsolePolyfill.cs +++ b/src/Split/net481/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net481/ConvertPolyfill.cs b/src/Split/net481/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/net481/ConvertPolyfill.cs +++ b/src/Split/net481/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net481/DateTimeOffsetPolyfill.cs b/src/Split/net481/DateTimeOffsetPolyfill.cs index 6837790e..7bb9a5ad 100644 --- a/src/Split/net481/DateTimeOffsetPolyfill.cs +++ b/src/Split/net481/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,32 +31,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net481/DateTimePolyfill.cs b/src/Split/net481/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/net481/DateTimePolyfill.cs +++ b/src/Split/net481/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net481/DelegatePolyfill.cs b/src/Split/net481/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net481/DelegatePolyfill.cs +++ b/src/Split/net481/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net481/FilePolyfill.cs b/src/Split/net481/FilePolyfill.cs index c6112e74..66cb81a1 100644 --- a/src/Split/net481/FilePolyfill.cs +++ b/src/Split/net481/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net481/GuidPolyfill.cs b/src/Split/net481/GuidPolyfill.cs index 2bd53673..bc6b9129 100644 --- a/src/Split/net481/GuidPolyfill.cs +++ b/src/Split/net481/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, out Guid result) => Guid.TryParseExact(input.ToString(), format.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net481/KeyValuePair.cs b/src/Split/net481/KeyValuePair.cs index 7e5d5895..e94cbbf2 100644 --- a/src/Split/net481/KeyValuePair.cs +++ b/src/Split/net481/KeyValuePair.cs @@ -4,6 +4,7 @@ namespace System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; [ExcludeFromCodeCoverage] [DebuggerNonUserCode] #if PolyUseEmbeddedAttribute @@ -17,6 +18,7 @@ static class KeyValuePair /// /// Creates a new key/value pair instance using provided values. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static KeyValuePair Create(TKey key, TValue value) => new(key, value); } diff --git a/src/Split/net481/Lock.cs b/src/Split/net481/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net481/Lock.cs +++ b/src/Split/net481/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net481/Numbers/BytePolyfill.cs b/src/Split/net481/Numbers/BytePolyfill.cs index ef3f744e..0ea017af 100644 --- a/src/Split/net481/Numbers/BytePolyfill.cs +++ b/src/Split/net481/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,37 +13,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out byte result) => byte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif diff --git a/src/Split/net481/Numbers/DoublePolyfill.cs b/src/Split/net481/Numbers/DoublePolyfill.cs index ba5333f6..d903ddfe 100644 --- a/src/Split/net481/Numbers/DoublePolyfill.cs +++ b/src/Split/net481/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out double result) => double.TryParse(s.ToString(), out result); /// /// Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/net481/Numbers/Int16Polyfill.cs b/src/Split/net481/Numbers/Int16Polyfill.cs index 5eb1b384..960cf68c 100644 --- a/src/Split/net481/Numbers/Int16Polyfill.cs +++ b/src/Split/net481/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out short result) => short.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net481/Numbers/Int32Polyfill.cs b/src/Split/net481/Numbers/Int32Polyfill.cs index 549ff189..2920eae4 100644 --- a/src/Split/net481/Numbers/Int32Polyfill.cs +++ b/src/Split/net481/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out int result) => int.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net481/Numbers/Int64Polyfill.cs b/src/Split/net481/Numbers/Int64Polyfill.cs index bd33ce0e..0b7b1b10 100644 --- a/src/Split/net481/Numbers/Int64Polyfill.cs +++ b/src/Split/net481/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out long result) => long.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net481/Numbers/SBytePolyfill.cs b/src/Split/net481/Numbers/SBytePolyfill.cs index 97411565..890452b1 100644 --- a/src/Split/net481/Numbers/SBytePolyfill.cs +++ b/src/Split/net481/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out sbyte result) => sbyte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net481/Numbers/UInt16Polyfill.cs b/src/Split/net481/Numbers/UInt16Polyfill.cs index 34f39f97..ed095880 100644 --- a/src/Split/net481/Numbers/UInt16Polyfill.cs +++ b/src/Split/net481/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ushort result) => ushort.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net481/Numbers/UInt32Polyfill.cs b/src/Split/net481/Numbers/UInt32Polyfill.cs index 859149be..e11b65c9 100644 --- a/src/Split/net481/Numbers/UInt32Polyfill.cs +++ b/src/Split/net481/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out uint result) => uint.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net481/Numbers/UInt64Polyfill.cs b/src/Split/net481/Numbers/UInt64Polyfill.cs index c14bb347..10122d2b 100644 --- a/src/Split/net481/Numbers/UInt64Polyfill.cs +++ b/src/Split/net481/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ulong result) => ulong.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net481/OperatingSystemPolyfill.cs b/src/Split/net481/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/net481/OperatingSystemPolyfill.cs +++ b/src/Split/net481/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/net481/PathPolyfill.cs b/src/Split/net481/PathPolyfill.cs index fb4329ac..fc8009da 100644 --- a/src/Split/net481/PathPolyfill.cs +++ b/src/Split/net481/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,41 +12,49 @@ static partial class Polyfill /// /// Returns the directory information for the specified path represented by a character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetDirectoryName(ReadOnlySpan path) => Path.GetDirectoryName(path.ToString()).AsSpan(); /// /// Returns the file name and extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileName(ReadOnlySpan path) => Path.GetFileName(path.ToString()).AsSpan(); /// /// Returns the file name without the extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) => Path.GetFileNameWithoutExtension(path.ToString()).AsSpan(); /// /// Determines whether the path represented by the specified character span includes a file name extension. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasExtension(ReadOnlySpan path) => Path.HasExtension(path.ToString()); /// /// Returns the extension of the given path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetExtension(ReadOnlySpan path) => Path.GetExtension(path.ToString()).AsSpan(); /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/net5.0/ConsolePolyfill.cs b/src/Split/net5.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net5.0/ConsolePolyfill.cs +++ b/src/Split/net5.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net5.0/ConvertPolyfill.cs b/src/Split/net5.0/ConvertPolyfill.cs index 2ba95a78..0744e77d 100644 --- a/src/Split/net5.0/ConvertPolyfill.cs +++ b/src/Split/net5.0/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,17 +11,20 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); #if FeatureMemory /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net5.0/DateTimeOffsetPolyfill.cs b/src/Split/net5.0/DateTimeOffsetPolyfill.cs index 15ba54f7..add60f3a 100644 --- a/src/Split/net5.0/DateTimeOffsetPolyfill.cs +++ b/src/Split/net5.0/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,12 +31,14 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); #endif diff --git a/src/Split/net5.0/DateTimePolyfill.cs b/src/Split/net5.0/DateTimePolyfill.cs index 8eb8c705..29ae6c62 100644 --- a/src/Split/net5.0/DateTimePolyfill.cs +++ b/src/Split/net5.0/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,17 +30,20 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net5.0/DelegatePolyfill.cs b/src/Split/net5.0/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net5.0/DelegatePolyfill.cs +++ b/src/Split/net5.0/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net5.0/FilePolyfill.cs b/src/Split/net5.0/FilePolyfill.cs index ff68c4d3..66d68b0a 100644 --- a/src/Split/net5.0/FilePolyfill.cs +++ b/src/Split/net5.0/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net5.0/GuidPolyfill.cs b/src/Split/net5.0/GuidPolyfill.cs index c61f6972..44d9c654 100644 --- a/src/Split/net5.0/GuidPolyfill.cs +++ b/src/Split/net5.0/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,16 +43,19 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net5.0/Lock.cs b/src/Split/net5.0/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net5.0/Lock.cs +++ b/src/Split/net5.0/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net5.0/Numbers/BytePolyfill.cs b/src/Split/net5.0/Numbers/BytePolyfill.cs index b3235149..fd1d5aa6 100644 --- a/src/Split/net5.0/Numbers/BytePolyfill.cs +++ b/src/Split/net5.0/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,27 +13,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/net5.0/Numbers/DoublePolyfill.cs b/src/Split/net5.0/Numbers/DoublePolyfill.cs index ff9f8aca..94b44e86 100644 --- a/src/Split/net5.0/Numbers/DoublePolyfill.cs +++ b/src/Split/net5.0/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/net5.0/Numbers/Int16Polyfill.cs b/src/Split/net5.0/Numbers/Int16Polyfill.cs index 7a1f0b7c..4447a9ec 100644 --- a/src/Split/net5.0/Numbers/Int16Polyfill.cs +++ b/src/Split/net5.0/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net5.0/Numbers/Int32Polyfill.cs b/src/Split/net5.0/Numbers/Int32Polyfill.cs index 853dfb51..587b2be9 100644 --- a/src/Split/net5.0/Numbers/Int32Polyfill.cs +++ b/src/Split/net5.0/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net5.0/Numbers/Int64Polyfill.cs b/src/Split/net5.0/Numbers/Int64Polyfill.cs index e97be477..3d7b5c57 100644 --- a/src/Split/net5.0/Numbers/Int64Polyfill.cs +++ b/src/Split/net5.0/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net5.0/Numbers/SBytePolyfill.cs b/src/Split/net5.0/Numbers/SBytePolyfill.cs index 9085c3ae..8de2ac07 100644 --- a/src/Split/net5.0/Numbers/SBytePolyfill.cs +++ b/src/Split/net5.0/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net5.0/Numbers/UInt16Polyfill.cs b/src/Split/net5.0/Numbers/UInt16Polyfill.cs index 11d4c4ed..b3b68b25 100644 --- a/src/Split/net5.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/net5.0/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net5.0/Numbers/UInt32Polyfill.cs b/src/Split/net5.0/Numbers/UInt32Polyfill.cs index abdf707d..4ba985db 100644 --- a/src/Split/net5.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/net5.0/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net5.0/Numbers/UInt64Polyfill.cs b/src/Split/net5.0/Numbers/UInt64Polyfill.cs index 1a1bc228..08e8b0fa 100644 --- a/src/Split/net5.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/net5.0/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net5.0/OperatingSystemPolyfill.cs b/src/Split/net5.0/OperatingSystemPolyfill.cs index ebb874ff..c995c6be 100644 --- a/src/Split/net5.0/OperatingSystemPolyfill.cs +++ b/src/Split/net5.0/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,17 +15,20 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); diff --git a/src/Split/net5.0/PathPolyfill.cs b/src/Split/net5.0/PathPolyfill.cs index 268c89cf..39af8750 100644 --- a/src/Split/net5.0/PathPolyfill.cs +++ b/src/Split/net5.0/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,6 +12,7 @@ static partial class Polyfill /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); #endif diff --git a/src/Split/net6.0/ConsolePolyfill.cs b/src/Split/net6.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net6.0/ConsolePolyfill.cs +++ b/src/Split/net6.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net6.0/ConvertPolyfill.cs b/src/Split/net6.0/ConvertPolyfill.cs index 2ba95a78..0744e77d 100644 --- a/src/Split/net6.0/ConvertPolyfill.cs +++ b/src/Split/net6.0/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,17 +11,20 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); #if FeatureMemory /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net6.0/DateTimeOffsetPolyfill.cs b/src/Split/net6.0/DateTimeOffsetPolyfill.cs index 15ba54f7..add60f3a 100644 --- a/src/Split/net6.0/DateTimeOffsetPolyfill.cs +++ b/src/Split/net6.0/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,12 +31,14 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); #endif diff --git a/src/Split/net6.0/DateTimePolyfill.cs b/src/Split/net6.0/DateTimePolyfill.cs index 8eb8c705..29ae6c62 100644 --- a/src/Split/net6.0/DateTimePolyfill.cs +++ b/src/Split/net6.0/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,17 +30,20 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net6.0/DelegatePolyfill.cs b/src/Split/net6.0/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net6.0/DelegatePolyfill.cs +++ b/src/Split/net6.0/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net6.0/FilePolyfill.cs b/src/Split/net6.0/FilePolyfill.cs index 87911de4..376bbc2b 100644 --- a/src/Split/net6.0/FilePolyfill.cs +++ b/src/Split/net6.0/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net6.0/GuidPolyfill.cs b/src/Split/net6.0/GuidPolyfill.cs index c61f6972..44d9c654 100644 --- a/src/Split/net6.0/GuidPolyfill.cs +++ b/src/Split/net6.0/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,16 +43,19 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net6.0/Lock.cs b/src/Split/net6.0/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net6.0/Lock.cs +++ b/src/Split/net6.0/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net6.0/Numbers/BytePolyfill.cs b/src/Split/net6.0/Numbers/BytePolyfill.cs index b3235149..fd1d5aa6 100644 --- a/src/Split/net6.0/Numbers/BytePolyfill.cs +++ b/src/Split/net6.0/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,27 +13,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/net6.0/Numbers/DoublePolyfill.cs b/src/Split/net6.0/Numbers/DoublePolyfill.cs index ff9f8aca..94b44e86 100644 --- a/src/Split/net6.0/Numbers/DoublePolyfill.cs +++ b/src/Split/net6.0/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/net6.0/Numbers/Int16Polyfill.cs b/src/Split/net6.0/Numbers/Int16Polyfill.cs index 7a1f0b7c..4447a9ec 100644 --- a/src/Split/net6.0/Numbers/Int16Polyfill.cs +++ b/src/Split/net6.0/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net6.0/Numbers/Int32Polyfill.cs b/src/Split/net6.0/Numbers/Int32Polyfill.cs index 853dfb51..587b2be9 100644 --- a/src/Split/net6.0/Numbers/Int32Polyfill.cs +++ b/src/Split/net6.0/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net6.0/Numbers/Int64Polyfill.cs b/src/Split/net6.0/Numbers/Int64Polyfill.cs index e97be477..3d7b5c57 100644 --- a/src/Split/net6.0/Numbers/Int64Polyfill.cs +++ b/src/Split/net6.0/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net6.0/Numbers/SBytePolyfill.cs b/src/Split/net6.0/Numbers/SBytePolyfill.cs index 9085c3ae..8de2ac07 100644 --- a/src/Split/net6.0/Numbers/SBytePolyfill.cs +++ b/src/Split/net6.0/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net6.0/Numbers/UInt16Polyfill.cs b/src/Split/net6.0/Numbers/UInt16Polyfill.cs index 11d4c4ed..b3b68b25 100644 --- a/src/Split/net6.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/net6.0/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net6.0/Numbers/UInt32Polyfill.cs b/src/Split/net6.0/Numbers/UInt32Polyfill.cs index abdf707d..4ba985db 100644 --- a/src/Split/net6.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/net6.0/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net6.0/Numbers/UInt64Polyfill.cs b/src/Split/net6.0/Numbers/UInt64Polyfill.cs index 1a1bc228..08e8b0fa 100644 --- a/src/Split/net6.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/net6.0/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/net6.0/OperatingSystemPolyfill.cs b/src/Split/net6.0/OperatingSystemPolyfill.cs index b444ca73..38650120 100644 --- a/src/Split/net6.0/OperatingSystemPolyfill.cs +++ b/src/Split/net6.0/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,6 +15,7 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); } diff --git a/src/Split/net6.0/PathPolyfill.cs b/src/Split/net6.0/PathPolyfill.cs index 268c89cf..39af8750 100644 --- a/src/Split/net6.0/PathPolyfill.cs +++ b/src/Split/net6.0/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,6 +12,7 @@ static partial class Polyfill /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); #endif diff --git a/src/Split/net7.0/ConsolePolyfill.cs b/src/Split/net7.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net7.0/ConsolePolyfill.cs +++ b/src/Split/net7.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net7.0/ConvertPolyfill.cs b/src/Split/net7.0/ConvertPolyfill.cs index 2ba95a78..0744e77d 100644 --- a/src/Split/net7.0/ConvertPolyfill.cs +++ b/src/Split/net7.0/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,17 +11,20 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); #if FeatureMemory /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net7.0/DateTimeOffsetPolyfill.cs b/src/Split/net7.0/DateTimeOffsetPolyfill.cs index 78c58e2d..55d09893 100644 --- a/src/Split/net7.0/DateTimeOffsetPolyfill.cs +++ b/src/Split/net7.0/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset) @@ -12,6 +13,7 @@ static partial class Polyfill /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); #endif diff --git a/src/Split/net7.0/DateTimePolyfill.cs b/src/Split/net7.0/DateTimePolyfill.cs index 6a3cb556..48f71f97 100644 --- a/src/Split/net7.0/DateTimePolyfill.cs +++ b/src/Split/net7.0/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime) @@ -11,11 +12,13 @@ static partial class Polyfill /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/net7.0/DelegatePolyfill.cs b/src/Split/net7.0/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net7.0/DelegatePolyfill.cs +++ b/src/Split/net7.0/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net7.0/FilePolyfill.cs b/src/Split/net7.0/FilePolyfill.cs index cd559610..1762c39c 100644 --- a/src/Split/net7.0/FilePolyfill.cs +++ b/src/Split/net7.0/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net7.0/GuidPolyfill.cs b/src/Split/net7.0/GuidPolyfill.cs index 42acf37e..d98f66f9 100644 --- a/src/Split/net7.0/GuidPolyfill.cs +++ b/src/Split/net7.0/GuidPolyfill.cs @@ -4,11 +4,13 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) { /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -35,11 +37,13 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net7.0/Lock.cs b/src/Split/net7.0/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net7.0/Lock.cs +++ b/src/Split/net7.0/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net7.0/Numbers/BytePolyfill.cs b/src/Split/net7.0/Numbers/BytePolyfill.cs index 572eab88..142f2c3e 100644 --- a/src/Split/net7.0/Numbers/BytePolyfill.cs +++ b/src/Split/net7.0/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -13,16 +14,19 @@ static partial class Polyfill /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/net7.0/Numbers/DoublePolyfill.cs b/src/Split/net7.0/Numbers/DoublePolyfill.cs index 53d86a1a..d9844918 100644 --- a/src/Split/net7.0/Numbers/DoublePolyfill.cs +++ b/src/Split/net7.0/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); #endif diff --git a/src/Split/net7.0/Numbers/Int16Polyfill.cs b/src/Split/net7.0/Numbers/Int16Polyfill.cs index c87eac7f..cc662020 100644 --- a/src/Split/net7.0/Numbers/Int16Polyfill.cs +++ b/src/Split/net7.0/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/net7.0/Numbers/Int32Polyfill.cs b/src/Split/net7.0/Numbers/Int32Polyfill.cs index 9e07d4b5..8196cec1 100644 --- a/src/Split/net7.0/Numbers/Int32Polyfill.cs +++ b/src/Split/net7.0/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/net7.0/Numbers/Int64Polyfill.cs b/src/Split/net7.0/Numbers/Int64Polyfill.cs index 3c23329b..5f047e81 100644 --- a/src/Split/net7.0/Numbers/Int64Polyfill.cs +++ b/src/Split/net7.0/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/net7.0/Numbers/SBytePolyfill.cs b/src/Split/net7.0/Numbers/SBytePolyfill.cs index 488c8b8e..f128a0a8 100644 --- a/src/Split/net7.0/Numbers/SBytePolyfill.cs +++ b/src/Split/net7.0/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/net7.0/Numbers/UInt16Polyfill.cs b/src/Split/net7.0/Numbers/UInt16Polyfill.cs index 347c4a42..826d2fe8 100644 --- a/src/Split/net7.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/net7.0/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/net7.0/Numbers/UInt32Polyfill.cs b/src/Split/net7.0/Numbers/UInt32Polyfill.cs index fc6b0672..21b64bd1 100644 --- a/src/Split/net7.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/net7.0/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/net7.0/Numbers/UInt64Polyfill.cs b/src/Split/net7.0/Numbers/UInt64Polyfill.cs index 96cf2e21..ace06b31 100644 --- a/src/Split/net7.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/net7.0/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/net7.0/OperatingSystemPolyfill.cs b/src/Split/net7.0/OperatingSystemPolyfill.cs index b444ca73..38650120 100644 --- a/src/Split/net7.0/OperatingSystemPolyfill.cs +++ b/src/Split/net7.0/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,6 +15,7 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); } diff --git a/src/Split/net7.0/PathPolyfill.cs b/src/Split/net7.0/PathPolyfill.cs index 9cb9a871..19d455dc 100644 --- a/src/Split/net7.0/PathPolyfill.cs +++ b/src/Split/net7.0/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,6 +12,7 @@ static partial class Polyfill /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); #endif diff --git a/src/Split/net8.0/ConsolePolyfill.cs b/src/Split/net8.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net8.0/ConsolePolyfill.cs +++ b/src/Split/net8.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net8.0/ConvertPolyfill.cs b/src/Split/net8.0/ConvertPolyfill.cs index 2ba95a78..0744e77d 100644 --- a/src/Split/net8.0/ConvertPolyfill.cs +++ b/src/Split/net8.0/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,17 +11,20 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); #if FeatureMemory /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/net8.0/DelegatePolyfill.cs b/src/Split/net8.0/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/net8.0/DelegatePolyfill.cs +++ b/src/Split/net8.0/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/net8.0/FilePolyfill.cs b/src/Split/net8.0/FilePolyfill.cs index cd559610..1762c39c 100644 --- a/src/Split/net8.0/FilePolyfill.cs +++ b/src/Split/net8.0/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/net8.0/GuidPolyfill.cs b/src/Split/net8.0/GuidPolyfill.cs index 7666507b..2f515013 100644 --- a/src/Split/net8.0/GuidPolyfill.cs +++ b/src/Split/net8.0/GuidPolyfill.cs @@ -4,11 +4,13 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) { /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -31,11 +33,13 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/net8.0/Lock.cs b/src/Split/net8.0/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/net8.0/Lock.cs +++ b/src/Split/net8.0/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/net8.0/PathPolyfill.cs b/src/Split/net8.0/PathPolyfill.cs index 9cb9a871..19d455dc 100644 --- a/src/Split/net8.0/PathPolyfill.cs +++ b/src/Split/net8.0/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,6 +12,7 @@ static partial class Polyfill /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); #endif diff --git a/src/Split/net9.0/ConsolePolyfill.cs b/src/Split/net9.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/net9.0/ConsolePolyfill.cs +++ b/src/Split/net9.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/net9.0/GuidPolyfill.cs b/src/Split/net9.0/GuidPolyfill.cs index ff436246..df4f5db1 100644 --- a/src/Split/net9.0/GuidPolyfill.cs +++ b/src/Split/net9.0/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -12,11 +13,13 @@ static partial class Polyfill /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/netcoreapp2.0/ConsolePolyfill.cs b/src/Split/netcoreapp2.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/netcoreapp2.0/ConsolePolyfill.cs +++ b/src/Split/netcoreapp2.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/netcoreapp2.0/ConvertPolyfill.cs b/src/Split/netcoreapp2.0/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/netcoreapp2.0/ConvertPolyfill.cs +++ b/src/Split/netcoreapp2.0/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/netcoreapp2.0/DateTimeOffsetPolyfill.cs b/src/Split/netcoreapp2.0/DateTimeOffsetPolyfill.cs index 6837790e..7bb9a5ad 100644 --- a/src/Split/netcoreapp2.0/DateTimeOffsetPolyfill.cs +++ b/src/Split/netcoreapp2.0/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,32 +31,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/netcoreapp2.0/DateTimePolyfill.cs b/src/Split/netcoreapp2.0/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/netcoreapp2.0/DateTimePolyfill.cs +++ b/src/Split/netcoreapp2.0/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/netcoreapp2.0/DelegatePolyfill.cs b/src/Split/netcoreapp2.0/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/netcoreapp2.0/DelegatePolyfill.cs +++ b/src/Split/netcoreapp2.0/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/netcoreapp2.0/FilePolyfill.cs b/src/Split/netcoreapp2.0/FilePolyfill.cs index 3e55baa2..fa568149 100644 --- a/src/Split/netcoreapp2.0/FilePolyfill.cs +++ b/src/Split/netcoreapp2.0/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/netcoreapp2.0/GuidPolyfill.cs b/src/Split/netcoreapp2.0/GuidPolyfill.cs index 2bd53673..bc6b9129 100644 --- a/src/Split/netcoreapp2.0/GuidPolyfill.cs +++ b/src/Split/netcoreapp2.0/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, out Guid result) => Guid.TryParseExact(input.ToString(), format.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/netcoreapp2.0/Lock.cs b/src/Split/netcoreapp2.0/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/netcoreapp2.0/Lock.cs +++ b/src/Split/netcoreapp2.0/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/netcoreapp2.0/Numbers/BytePolyfill.cs b/src/Split/netcoreapp2.0/Numbers/BytePolyfill.cs index ef3f744e..0ea017af 100644 --- a/src/Split/netcoreapp2.0/Numbers/BytePolyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,37 +13,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out byte result) => byte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif diff --git a/src/Split/netcoreapp2.0/Numbers/DoublePolyfill.cs b/src/Split/netcoreapp2.0/Numbers/DoublePolyfill.cs index ba5333f6..d903ddfe 100644 --- a/src/Split/netcoreapp2.0/Numbers/DoublePolyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out double result) => double.TryParse(s.ToString(), out result); /// /// Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/netcoreapp2.0/Numbers/Int16Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/Int16Polyfill.cs index 5eb1b384..960cf68c 100644 --- a/src/Split/netcoreapp2.0/Numbers/Int16Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out short result) => short.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.0/Numbers/Int32Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/Int32Polyfill.cs index 549ff189..2920eae4 100644 --- a/src/Split/netcoreapp2.0/Numbers/Int32Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out int result) => int.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.0/Numbers/Int64Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/Int64Polyfill.cs index bd33ce0e..0b7b1b10 100644 --- a/src/Split/netcoreapp2.0/Numbers/Int64Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out long result) => long.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.0/Numbers/SBytePolyfill.cs b/src/Split/netcoreapp2.0/Numbers/SBytePolyfill.cs index 97411565..890452b1 100644 --- a/src/Split/netcoreapp2.0/Numbers/SBytePolyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out sbyte result) => sbyte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.0/Numbers/UInt16Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/UInt16Polyfill.cs index 34f39f97..ed095880 100644 --- a/src/Split/netcoreapp2.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ushort result) => ushort.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.0/Numbers/UInt32Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/UInt32Polyfill.cs index 859149be..e11b65c9 100644 --- a/src/Split/netcoreapp2.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out uint result) => uint.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.0/Numbers/UInt64Polyfill.cs b/src/Split/netcoreapp2.0/Numbers/UInt64Polyfill.cs index c14bb347..10122d2b 100644 --- a/src/Split/netcoreapp2.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/netcoreapp2.0/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ulong result) => ulong.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.0/OperatingSystemPolyfill.cs b/src/Split/netcoreapp2.0/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/netcoreapp2.0/OperatingSystemPolyfill.cs +++ b/src/Split/netcoreapp2.0/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/netcoreapp2.0/PathPolyfill.cs b/src/Split/netcoreapp2.0/PathPolyfill.cs index fb4329ac..fc8009da 100644 --- a/src/Split/netcoreapp2.0/PathPolyfill.cs +++ b/src/Split/netcoreapp2.0/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,41 +12,49 @@ static partial class Polyfill /// /// Returns the directory information for the specified path represented by a character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetDirectoryName(ReadOnlySpan path) => Path.GetDirectoryName(path.ToString()).AsSpan(); /// /// Returns the file name and extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileName(ReadOnlySpan path) => Path.GetFileName(path.ToString()).AsSpan(); /// /// Returns the file name without the extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) => Path.GetFileNameWithoutExtension(path.ToString()).AsSpan(); /// /// Determines whether the path represented by the specified character span includes a file name extension. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasExtension(ReadOnlySpan path) => Path.HasExtension(path.ToString()); /// /// Returns the extension of the given path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetExtension(ReadOnlySpan path) => Path.GetExtension(path.ToString()).AsSpan(); /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/netcoreapp2.1/ConsolePolyfill.cs b/src/Split/netcoreapp2.1/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/netcoreapp2.1/ConsolePolyfill.cs +++ b/src/Split/netcoreapp2.1/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/netcoreapp2.1/ConvertPolyfill.cs b/src/Split/netcoreapp2.1/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/netcoreapp2.1/ConvertPolyfill.cs +++ b/src/Split/netcoreapp2.1/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/netcoreapp2.1/DateTimeOffsetPolyfill.cs b/src/Split/netcoreapp2.1/DateTimeOffsetPolyfill.cs index 5a501820..11ea73e0 100644 --- a/src/Split/netcoreapp2.1/DateTimeOffsetPolyfill.cs +++ b/src/Split/netcoreapp2.1/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,27 +31,32 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); #endif diff --git a/src/Split/netcoreapp2.1/DateTimePolyfill.cs b/src/Split/netcoreapp2.1/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/netcoreapp2.1/DateTimePolyfill.cs +++ b/src/Split/netcoreapp2.1/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/netcoreapp2.1/DelegatePolyfill.cs b/src/Split/netcoreapp2.1/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/netcoreapp2.1/DelegatePolyfill.cs +++ b/src/Split/netcoreapp2.1/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/netcoreapp2.1/FilePolyfill.cs b/src/Split/netcoreapp2.1/FilePolyfill.cs index 3e55baa2..fa568149 100644 --- a/src/Split/netcoreapp2.1/FilePolyfill.cs +++ b/src/Split/netcoreapp2.1/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/netcoreapp2.1/GuidPolyfill.cs b/src/Split/netcoreapp2.1/GuidPolyfill.cs index a29acf18..90b6c9f4 100644 --- a/src/Split/netcoreapp2.1/GuidPolyfill.cs +++ b/src/Split/netcoreapp2.1/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,21 +43,25 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/netcoreapp2.1/Lock.cs b/src/Split/netcoreapp2.1/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/netcoreapp2.1/Lock.cs +++ b/src/Split/netcoreapp2.1/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/netcoreapp2.1/Numbers/BytePolyfill.cs b/src/Split/netcoreapp2.1/Numbers/BytePolyfill.cs index b3235149..fd1d5aa6 100644 --- a/src/Split/netcoreapp2.1/Numbers/BytePolyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,27 +13,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/netcoreapp2.1/Numbers/DoublePolyfill.cs b/src/Split/netcoreapp2.1/Numbers/DoublePolyfill.cs index ff9f8aca..94b44e86 100644 --- a/src/Split/netcoreapp2.1/Numbers/DoublePolyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/netcoreapp2.1/Numbers/Int16Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/Int16Polyfill.cs index 7a1f0b7c..4447a9ec 100644 --- a/src/Split/netcoreapp2.1/Numbers/Int16Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.1/Numbers/Int32Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/Int32Polyfill.cs index 853dfb51..587b2be9 100644 --- a/src/Split/netcoreapp2.1/Numbers/Int32Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.1/Numbers/Int64Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/Int64Polyfill.cs index e97be477..3d7b5c57 100644 --- a/src/Split/netcoreapp2.1/Numbers/Int64Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.1/Numbers/SBytePolyfill.cs b/src/Split/netcoreapp2.1/Numbers/SBytePolyfill.cs index 9085c3ae..8de2ac07 100644 --- a/src/Split/netcoreapp2.1/Numbers/SBytePolyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.1/Numbers/UInt16Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/UInt16Polyfill.cs index 11d4c4ed..b3b68b25 100644 --- a/src/Split/netcoreapp2.1/Numbers/UInt16Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.1/Numbers/UInt32Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/UInt32Polyfill.cs index abdf707d..4ba985db 100644 --- a/src/Split/netcoreapp2.1/Numbers/UInt32Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.1/Numbers/UInt64Polyfill.cs b/src/Split/netcoreapp2.1/Numbers/UInt64Polyfill.cs index 1a1bc228..08e8b0fa 100644 --- a/src/Split/netcoreapp2.1/Numbers/UInt64Polyfill.cs +++ b/src/Split/netcoreapp2.1/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.1/OperatingSystemPolyfill.cs b/src/Split/netcoreapp2.1/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/netcoreapp2.1/OperatingSystemPolyfill.cs +++ b/src/Split/netcoreapp2.1/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/netcoreapp2.1/PathPolyfill.cs b/src/Split/netcoreapp2.1/PathPolyfill.cs index dc917864..607d9e14 100644 --- a/src/Split/netcoreapp2.1/PathPolyfill.cs +++ b/src/Split/netcoreapp2.1/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,16 +12,19 @@ static partial class Polyfill /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/netcoreapp2.2/ConsolePolyfill.cs b/src/Split/netcoreapp2.2/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/netcoreapp2.2/ConsolePolyfill.cs +++ b/src/Split/netcoreapp2.2/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/netcoreapp2.2/ConvertPolyfill.cs b/src/Split/netcoreapp2.2/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/netcoreapp2.2/ConvertPolyfill.cs +++ b/src/Split/netcoreapp2.2/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/netcoreapp2.2/DateTimeOffsetPolyfill.cs b/src/Split/netcoreapp2.2/DateTimeOffsetPolyfill.cs index 5a501820..11ea73e0 100644 --- a/src/Split/netcoreapp2.2/DateTimeOffsetPolyfill.cs +++ b/src/Split/netcoreapp2.2/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,27 +31,32 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); #endif diff --git a/src/Split/netcoreapp2.2/DateTimePolyfill.cs b/src/Split/netcoreapp2.2/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/netcoreapp2.2/DateTimePolyfill.cs +++ b/src/Split/netcoreapp2.2/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/netcoreapp2.2/DelegatePolyfill.cs b/src/Split/netcoreapp2.2/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/netcoreapp2.2/DelegatePolyfill.cs +++ b/src/Split/netcoreapp2.2/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/netcoreapp2.2/FilePolyfill.cs b/src/Split/netcoreapp2.2/FilePolyfill.cs index 3e55baa2..fa568149 100644 --- a/src/Split/netcoreapp2.2/FilePolyfill.cs +++ b/src/Split/netcoreapp2.2/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/netcoreapp2.2/GuidPolyfill.cs b/src/Split/netcoreapp2.2/GuidPolyfill.cs index a29acf18..90b6c9f4 100644 --- a/src/Split/netcoreapp2.2/GuidPolyfill.cs +++ b/src/Split/netcoreapp2.2/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,21 +43,25 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/netcoreapp2.2/Lock.cs b/src/Split/netcoreapp2.2/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/netcoreapp2.2/Lock.cs +++ b/src/Split/netcoreapp2.2/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/netcoreapp2.2/Numbers/BytePolyfill.cs b/src/Split/netcoreapp2.2/Numbers/BytePolyfill.cs index b3235149..fd1d5aa6 100644 --- a/src/Split/netcoreapp2.2/Numbers/BytePolyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,27 +13,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/netcoreapp2.2/Numbers/DoublePolyfill.cs b/src/Split/netcoreapp2.2/Numbers/DoublePolyfill.cs index ff9f8aca..94b44e86 100644 --- a/src/Split/netcoreapp2.2/Numbers/DoublePolyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/netcoreapp2.2/Numbers/Int16Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/Int16Polyfill.cs index 7a1f0b7c..4447a9ec 100644 --- a/src/Split/netcoreapp2.2/Numbers/Int16Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.2/Numbers/Int32Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/Int32Polyfill.cs index 853dfb51..587b2be9 100644 --- a/src/Split/netcoreapp2.2/Numbers/Int32Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.2/Numbers/Int64Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/Int64Polyfill.cs index e97be477..3d7b5c57 100644 --- a/src/Split/netcoreapp2.2/Numbers/Int64Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.2/Numbers/SBytePolyfill.cs b/src/Split/netcoreapp2.2/Numbers/SBytePolyfill.cs index 9085c3ae..8de2ac07 100644 --- a/src/Split/netcoreapp2.2/Numbers/SBytePolyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.2/Numbers/UInt16Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/UInt16Polyfill.cs index 11d4c4ed..b3b68b25 100644 --- a/src/Split/netcoreapp2.2/Numbers/UInt16Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.2/Numbers/UInt32Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/UInt32Polyfill.cs index abdf707d..4ba985db 100644 --- a/src/Split/netcoreapp2.2/Numbers/UInt32Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.2/Numbers/UInt64Polyfill.cs b/src/Split/netcoreapp2.2/Numbers/UInt64Polyfill.cs index 1a1bc228..08e8b0fa 100644 --- a/src/Split/netcoreapp2.2/Numbers/UInt64Polyfill.cs +++ b/src/Split/netcoreapp2.2/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp2.2/OperatingSystemPolyfill.cs b/src/Split/netcoreapp2.2/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/netcoreapp2.2/OperatingSystemPolyfill.cs +++ b/src/Split/netcoreapp2.2/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/netcoreapp2.2/PathPolyfill.cs b/src/Split/netcoreapp2.2/PathPolyfill.cs index dc917864..607d9e14 100644 --- a/src/Split/netcoreapp2.2/PathPolyfill.cs +++ b/src/Split/netcoreapp2.2/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,16 +12,19 @@ static partial class Polyfill /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/netcoreapp3.0/ConsolePolyfill.cs b/src/Split/netcoreapp3.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/netcoreapp3.0/ConsolePolyfill.cs +++ b/src/Split/netcoreapp3.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/netcoreapp3.0/ConvertPolyfill.cs b/src/Split/netcoreapp3.0/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/netcoreapp3.0/ConvertPolyfill.cs +++ b/src/Split/netcoreapp3.0/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/netcoreapp3.0/DateTimeOffsetPolyfill.cs b/src/Split/netcoreapp3.0/DateTimeOffsetPolyfill.cs index 5a501820..11ea73e0 100644 --- a/src/Split/netcoreapp3.0/DateTimeOffsetPolyfill.cs +++ b/src/Split/netcoreapp3.0/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,27 +31,32 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); #endif diff --git a/src/Split/netcoreapp3.0/DateTimePolyfill.cs b/src/Split/netcoreapp3.0/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/netcoreapp3.0/DateTimePolyfill.cs +++ b/src/Split/netcoreapp3.0/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/netcoreapp3.0/DelegatePolyfill.cs b/src/Split/netcoreapp3.0/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/netcoreapp3.0/DelegatePolyfill.cs +++ b/src/Split/netcoreapp3.0/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/netcoreapp3.0/FilePolyfill.cs b/src/Split/netcoreapp3.0/FilePolyfill.cs index ff68c4d3..66d68b0a 100644 --- a/src/Split/netcoreapp3.0/FilePolyfill.cs +++ b/src/Split/netcoreapp3.0/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/netcoreapp3.0/GuidPolyfill.cs b/src/Split/netcoreapp3.0/GuidPolyfill.cs index a29acf18..90b6c9f4 100644 --- a/src/Split/netcoreapp3.0/GuidPolyfill.cs +++ b/src/Split/netcoreapp3.0/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,21 +43,25 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/netcoreapp3.0/Lock.cs b/src/Split/netcoreapp3.0/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/netcoreapp3.0/Lock.cs +++ b/src/Split/netcoreapp3.0/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/netcoreapp3.0/Numbers/BytePolyfill.cs b/src/Split/netcoreapp3.0/Numbers/BytePolyfill.cs index b3235149..fd1d5aa6 100644 --- a/src/Split/netcoreapp3.0/Numbers/BytePolyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,27 +13,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/netcoreapp3.0/Numbers/DoublePolyfill.cs b/src/Split/netcoreapp3.0/Numbers/DoublePolyfill.cs index ff9f8aca..94b44e86 100644 --- a/src/Split/netcoreapp3.0/Numbers/DoublePolyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/netcoreapp3.0/Numbers/Int16Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/Int16Polyfill.cs index 7a1f0b7c..4447a9ec 100644 --- a/src/Split/netcoreapp3.0/Numbers/Int16Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.0/Numbers/Int32Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/Int32Polyfill.cs index 853dfb51..587b2be9 100644 --- a/src/Split/netcoreapp3.0/Numbers/Int32Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.0/Numbers/Int64Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/Int64Polyfill.cs index e97be477..3d7b5c57 100644 --- a/src/Split/netcoreapp3.0/Numbers/Int64Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.0/Numbers/SBytePolyfill.cs b/src/Split/netcoreapp3.0/Numbers/SBytePolyfill.cs index 9085c3ae..8de2ac07 100644 --- a/src/Split/netcoreapp3.0/Numbers/SBytePolyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.0/Numbers/UInt16Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/UInt16Polyfill.cs index 11d4c4ed..b3b68b25 100644 --- a/src/Split/netcoreapp3.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.0/Numbers/UInt32Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/UInt32Polyfill.cs index abdf707d..4ba985db 100644 --- a/src/Split/netcoreapp3.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.0/Numbers/UInt64Polyfill.cs b/src/Split/netcoreapp3.0/Numbers/UInt64Polyfill.cs index 1a1bc228..08e8b0fa 100644 --- a/src/Split/netcoreapp3.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/netcoreapp3.0/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.0/OperatingSystemPolyfill.cs b/src/Split/netcoreapp3.0/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/netcoreapp3.0/OperatingSystemPolyfill.cs +++ b/src/Split/netcoreapp3.0/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/netcoreapp3.0/PathPolyfill.cs b/src/Split/netcoreapp3.0/PathPolyfill.cs index 268c89cf..39af8750 100644 --- a/src/Split/netcoreapp3.0/PathPolyfill.cs +++ b/src/Split/netcoreapp3.0/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,6 +12,7 @@ static partial class Polyfill /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); #endif diff --git a/src/Split/netcoreapp3.1/ConsolePolyfill.cs b/src/Split/netcoreapp3.1/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/netcoreapp3.1/ConsolePolyfill.cs +++ b/src/Split/netcoreapp3.1/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/netcoreapp3.1/ConvertPolyfill.cs b/src/Split/netcoreapp3.1/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/netcoreapp3.1/ConvertPolyfill.cs +++ b/src/Split/netcoreapp3.1/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/netcoreapp3.1/DateTimeOffsetPolyfill.cs b/src/Split/netcoreapp3.1/DateTimeOffsetPolyfill.cs index 5a501820..11ea73e0 100644 --- a/src/Split/netcoreapp3.1/DateTimeOffsetPolyfill.cs +++ b/src/Split/netcoreapp3.1/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,27 +31,32 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); #endif diff --git a/src/Split/netcoreapp3.1/DateTimePolyfill.cs b/src/Split/netcoreapp3.1/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/netcoreapp3.1/DateTimePolyfill.cs +++ b/src/Split/netcoreapp3.1/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/netcoreapp3.1/DelegatePolyfill.cs b/src/Split/netcoreapp3.1/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/netcoreapp3.1/DelegatePolyfill.cs +++ b/src/Split/netcoreapp3.1/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/netcoreapp3.1/FilePolyfill.cs b/src/Split/netcoreapp3.1/FilePolyfill.cs index ff68c4d3..66d68b0a 100644 --- a/src/Split/netcoreapp3.1/FilePolyfill.cs +++ b/src/Split/netcoreapp3.1/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/netcoreapp3.1/GuidPolyfill.cs b/src/Split/netcoreapp3.1/GuidPolyfill.cs index a29acf18..90b6c9f4 100644 --- a/src/Split/netcoreapp3.1/GuidPolyfill.cs +++ b/src/Split/netcoreapp3.1/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,21 +43,25 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/netcoreapp3.1/Lock.cs b/src/Split/netcoreapp3.1/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/netcoreapp3.1/Lock.cs +++ b/src/Split/netcoreapp3.1/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/netcoreapp3.1/Numbers/BytePolyfill.cs b/src/Split/netcoreapp3.1/Numbers/BytePolyfill.cs index b3235149..fd1d5aa6 100644 --- a/src/Split/netcoreapp3.1/Numbers/BytePolyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,27 +13,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/netcoreapp3.1/Numbers/DoublePolyfill.cs b/src/Split/netcoreapp3.1/Numbers/DoublePolyfill.cs index ff9f8aca..94b44e86 100644 --- a/src/Split/netcoreapp3.1/Numbers/DoublePolyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/netcoreapp3.1/Numbers/Int16Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/Int16Polyfill.cs index 7a1f0b7c..4447a9ec 100644 --- a/src/Split/netcoreapp3.1/Numbers/Int16Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.1/Numbers/Int32Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/Int32Polyfill.cs index 853dfb51..587b2be9 100644 --- a/src/Split/netcoreapp3.1/Numbers/Int32Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.1/Numbers/Int64Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/Int64Polyfill.cs index e97be477..3d7b5c57 100644 --- a/src/Split/netcoreapp3.1/Numbers/Int64Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.1/Numbers/SBytePolyfill.cs b/src/Split/netcoreapp3.1/Numbers/SBytePolyfill.cs index 9085c3ae..8de2ac07 100644 --- a/src/Split/netcoreapp3.1/Numbers/SBytePolyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.1/Numbers/UInt16Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/UInt16Polyfill.cs index 11d4c4ed..b3b68b25 100644 --- a/src/Split/netcoreapp3.1/Numbers/UInt16Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.1/Numbers/UInt32Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/UInt32Polyfill.cs index abdf707d..4ba985db 100644 --- a/src/Split/netcoreapp3.1/Numbers/UInt32Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.1/Numbers/UInt64Polyfill.cs b/src/Split/netcoreapp3.1/Numbers/UInt64Polyfill.cs index 1a1bc228..08e8b0fa 100644 --- a/src/Split/netcoreapp3.1/Numbers/UInt64Polyfill.cs +++ b/src/Split/netcoreapp3.1/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netcoreapp3.1/OperatingSystemPolyfill.cs b/src/Split/netcoreapp3.1/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/netcoreapp3.1/OperatingSystemPolyfill.cs +++ b/src/Split/netcoreapp3.1/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/netcoreapp3.1/PathPolyfill.cs b/src/Split/netcoreapp3.1/PathPolyfill.cs index 268c89cf..39af8750 100644 --- a/src/Split/netcoreapp3.1/PathPolyfill.cs +++ b/src/Split/netcoreapp3.1/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,6 +12,7 @@ static partial class Polyfill /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); #endif diff --git a/src/Split/netstandard2.0/ConsolePolyfill.cs b/src/Split/netstandard2.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/netstandard2.0/ConsolePolyfill.cs +++ b/src/Split/netstandard2.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/netstandard2.0/ConvertPolyfill.cs b/src/Split/netstandard2.0/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/netstandard2.0/ConvertPolyfill.cs +++ b/src/Split/netstandard2.0/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/netstandard2.0/DateTimeOffsetPolyfill.cs b/src/Split/netstandard2.0/DateTimeOffsetPolyfill.cs index 6837790e..7bb9a5ad 100644 --- a/src/Split/netstandard2.0/DateTimeOffsetPolyfill.cs +++ b/src/Split/netstandard2.0/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,32 +31,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/netstandard2.0/DateTimePolyfill.cs b/src/Split/netstandard2.0/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/netstandard2.0/DateTimePolyfill.cs +++ b/src/Split/netstandard2.0/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/netstandard2.0/DelegatePolyfill.cs b/src/Split/netstandard2.0/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/netstandard2.0/DelegatePolyfill.cs +++ b/src/Split/netstandard2.0/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/netstandard2.0/FilePolyfill.cs b/src/Split/netstandard2.0/FilePolyfill.cs index 6dda0398..42fd2619 100644 --- a/src/Split/netstandard2.0/FilePolyfill.cs +++ b/src/Split/netstandard2.0/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/netstandard2.0/GuidPolyfill.cs b/src/Split/netstandard2.0/GuidPolyfill.cs index 2bd53673..bc6b9129 100644 --- a/src/Split/netstandard2.0/GuidPolyfill.cs +++ b/src/Split/netstandard2.0/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, out Guid result) => Guid.TryParseExact(input.ToString(), format.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/netstandard2.0/KeyValuePair.cs b/src/Split/netstandard2.0/KeyValuePair.cs index 7e5d5895..e94cbbf2 100644 --- a/src/Split/netstandard2.0/KeyValuePair.cs +++ b/src/Split/netstandard2.0/KeyValuePair.cs @@ -4,6 +4,7 @@ namespace System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; [ExcludeFromCodeCoverage] [DebuggerNonUserCode] #if PolyUseEmbeddedAttribute @@ -17,6 +18,7 @@ static class KeyValuePair /// /// Creates a new key/value pair instance using provided values. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static KeyValuePair Create(TKey key, TValue value) => new(key, value); } diff --git a/src/Split/netstandard2.0/Lock.cs b/src/Split/netstandard2.0/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/netstandard2.0/Lock.cs +++ b/src/Split/netstandard2.0/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/netstandard2.0/Numbers/BytePolyfill.cs b/src/Split/netstandard2.0/Numbers/BytePolyfill.cs index ef3f744e..0ea017af 100644 --- a/src/Split/netstandard2.0/Numbers/BytePolyfill.cs +++ b/src/Split/netstandard2.0/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,37 +13,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out byte result) => byte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif diff --git a/src/Split/netstandard2.0/Numbers/DoublePolyfill.cs b/src/Split/netstandard2.0/Numbers/DoublePolyfill.cs index ba5333f6..d903ddfe 100644 --- a/src/Split/netstandard2.0/Numbers/DoublePolyfill.cs +++ b/src/Split/netstandard2.0/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out double result) => double.TryParse(s.ToString(), out result); /// /// Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/netstandard2.0/Numbers/Int16Polyfill.cs b/src/Split/netstandard2.0/Numbers/Int16Polyfill.cs index 5eb1b384..960cf68c 100644 --- a/src/Split/netstandard2.0/Numbers/Int16Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out short result) => short.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.0/Numbers/Int32Polyfill.cs b/src/Split/netstandard2.0/Numbers/Int32Polyfill.cs index 549ff189..2920eae4 100644 --- a/src/Split/netstandard2.0/Numbers/Int32Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out int result) => int.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.0/Numbers/Int64Polyfill.cs b/src/Split/netstandard2.0/Numbers/Int64Polyfill.cs index bd33ce0e..0b7b1b10 100644 --- a/src/Split/netstandard2.0/Numbers/Int64Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out long result) => long.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.0/Numbers/SBytePolyfill.cs b/src/Split/netstandard2.0/Numbers/SBytePolyfill.cs index 97411565..890452b1 100644 --- a/src/Split/netstandard2.0/Numbers/SBytePolyfill.cs +++ b/src/Split/netstandard2.0/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out sbyte result) => sbyte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.0/Numbers/UInt16Polyfill.cs b/src/Split/netstandard2.0/Numbers/UInt16Polyfill.cs index 34f39f97..ed095880 100644 --- a/src/Split/netstandard2.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ushort result) => ushort.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.0/Numbers/UInt32Polyfill.cs b/src/Split/netstandard2.0/Numbers/UInt32Polyfill.cs index 859149be..e11b65c9 100644 --- a/src/Split/netstandard2.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out uint result) => uint.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.0/Numbers/UInt64Polyfill.cs b/src/Split/netstandard2.0/Numbers/UInt64Polyfill.cs index c14bb347..10122d2b 100644 --- a/src/Split/netstandard2.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/netstandard2.0/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ulong result) => ulong.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.0/OperatingSystemPolyfill.cs b/src/Split/netstandard2.0/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/netstandard2.0/OperatingSystemPolyfill.cs +++ b/src/Split/netstandard2.0/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/netstandard2.0/PathPolyfill.cs b/src/Split/netstandard2.0/PathPolyfill.cs index fb4329ac..fc8009da 100644 --- a/src/Split/netstandard2.0/PathPolyfill.cs +++ b/src/Split/netstandard2.0/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,41 +12,49 @@ static partial class Polyfill /// /// Returns the directory information for the specified path represented by a character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetDirectoryName(ReadOnlySpan path) => Path.GetDirectoryName(path.ToString()).AsSpan(); /// /// Returns the file name and extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileName(ReadOnlySpan path) => Path.GetFileName(path.ToString()).AsSpan(); /// /// Returns the file name without the extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) => Path.GetFileNameWithoutExtension(path.ToString()).AsSpan(); /// /// Determines whether the path represented by the specified character span includes a file name extension. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasExtension(ReadOnlySpan path) => Path.HasExtension(path.ToString()); /// /// Returns the extension of the given path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetExtension(ReadOnlySpan path) => Path.GetExtension(path.ToString()).AsSpan(); /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/netstandard2.1/ConsolePolyfill.cs b/src/Split/netstandard2.1/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/netstandard2.1/ConsolePolyfill.cs +++ b/src/Split/netstandard2.1/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/netstandard2.1/ConvertPolyfill.cs b/src/Split/netstandard2.1/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/netstandard2.1/ConvertPolyfill.cs +++ b/src/Split/netstandard2.1/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/netstandard2.1/DateTimeOffsetPolyfill.cs b/src/Split/netstandard2.1/DateTimeOffsetPolyfill.cs index 15ba54f7..add60f3a 100644 --- a/src/Split/netstandard2.1/DateTimeOffsetPolyfill.cs +++ b/src/Split/netstandard2.1/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,12 +31,14 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); #endif diff --git a/src/Split/netstandard2.1/DateTimePolyfill.cs b/src/Split/netstandard2.1/DateTimePolyfill.cs index 8eb8c705..29ae6c62 100644 --- a/src/Split/netstandard2.1/DateTimePolyfill.cs +++ b/src/Split/netstandard2.1/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,17 +30,20 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/netstandard2.1/DelegatePolyfill.cs b/src/Split/netstandard2.1/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/netstandard2.1/DelegatePolyfill.cs +++ b/src/Split/netstandard2.1/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/netstandard2.1/FilePolyfill.cs b/src/Split/netstandard2.1/FilePolyfill.cs index 3e55baa2..fa568149 100644 --- a/src/Split/netstandard2.1/FilePolyfill.cs +++ b/src/Split/netstandard2.1/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/netstandard2.1/GuidPolyfill.cs b/src/Split/netstandard2.1/GuidPolyfill.cs index c61f6972..44d9c654 100644 --- a/src/Split/netstandard2.1/GuidPolyfill.cs +++ b/src/Split/netstandard2.1/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,16 +43,19 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/netstandard2.1/Lock.cs b/src/Split/netstandard2.1/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/netstandard2.1/Lock.cs +++ b/src/Split/netstandard2.1/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/netstandard2.1/Numbers/BytePolyfill.cs b/src/Split/netstandard2.1/Numbers/BytePolyfill.cs index b3235149..fd1d5aa6 100644 --- a/src/Split/netstandard2.1/Numbers/BytePolyfill.cs +++ b/src/Split/netstandard2.1/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,27 +13,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); #endif diff --git a/src/Split/netstandard2.1/Numbers/DoublePolyfill.cs b/src/Split/netstandard2.1/Numbers/DoublePolyfill.cs index ff9f8aca..94b44e86 100644 --- a/src/Split/netstandard2.1/Numbers/DoublePolyfill.cs +++ b/src/Split/netstandard2.1/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/netstandard2.1/Numbers/Int16Polyfill.cs b/src/Split/netstandard2.1/Numbers/Int16Polyfill.cs index 7a1f0b7c..4447a9ec 100644 --- a/src/Split/netstandard2.1/Numbers/Int16Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.1/Numbers/Int32Polyfill.cs b/src/Split/netstandard2.1/Numbers/Int32Polyfill.cs index 853dfb51..587b2be9 100644 --- a/src/Split/netstandard2.1/Numbers/Int32Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.1/Numbers/Int64Polyfill.cs b/src/Split/netstandard2.1/Numbers/Int64Polyfill.cs index e97be477..3d7b5c57 100644 --- a/src/Split/netstandard2.1/Numbers/Int64Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.1/Numbers/SBytePolyfill.cs b/src/Split/netstandard2.1/Numbers/SBytePolyfill.cs index 9085c3ae..8de2ac07 100644 --- a/src/Split/netstandard2.1/Numbers/SBytePolyfill.cs +++ b/src/Split/netstandard2.1/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.1/Numbers/UInt16Polyfill.cs b/src/Split/netstandard2.1/Numbers/UInt16Polyfill.cs index 11d4c4ed..b3b68b25 100644 --- a/src/Split/netstandard2.1/Numbers/UInt16Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.1/Numbers/UInt32Polyfill.cs b/src/Split/netstandard2.1/Numbers/UInt32Polyfill.cs index abdf707d..4ba985db 100644 --- a/src/Split/netstandard2.1/Numbers/UInt32Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.1/Numbers/UInt64Polyfill.cs b/src/Split/netstandard2.1/Numbers/UInt64Polyfill.cs index 1a1bc228..08e8b0fa 100644 --- a/src/Split/netstandard2.1/Numbers/UInt64Polyfill.cs +++ b/src/Split/netstandard2.1/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,27 +12,32 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/netstandard2.1/OperatingSystemPolyfill.cs b/src/Split/netstandard2.1/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/netstandard2.1/OperatingSystemPolyfill.cs +++ b/src/Split/netstandard2.1/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/netstandard2.1/PathPolyfill.cs b/src/Split/netstandard2.1/PathPolyfill.cs index dc917864..607d9e14 100644 --- a/src/Split/netstandard2.1/PathPolyfill.cs +++ b/src/Split/netstandard2.1/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,16 +12,19 @@ static partial class Polyfill /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif diff --git a/src/Split/uap10.0/ConsolePolyfill.cs b/src/Split/uap10.0/ConsolePolyfill.cs index 425364db..5ad0342d 100644 --- a/src/Split/uap10.0/ConsolePolyfill.cs +++ b/src/Split/uap10.0/ConsolePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; static partial class Polyfill { @@ -12,16 +13,19 @@ static partial class Polyfill /// /// Gets a that wraps the operating system handle for standard input. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardInputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdInput); /// /// Gets a that wraps the operating system handle for standard output. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardOutputHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdOutput); /// /// Gets a that wraps the operating system handle for standard error. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SafeFileHandle OpenStandardErrorHandle() => StandardHandleHelper.GetStandardHandle(StandardHandleHelper.StdError); } diff --git a/src/Split/uap10.0/ConvertPolyfill.cs b/src/Split/uap10.0/ConvertPolyfill.cs index 8ca6da94..5f80df1f 100644 --- a/src/Split/uap10.0/ConvertPolyfill.cs +++ b/src/Split/uap10.0/ConvertPolyfill.cs @@ -2,6 +2,7 @@ #pragma warning disable namespace Polyfills; using System; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Convert) @@ -10,22 +11,26 @@ static partial class Polyfill /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "X2"); /// /// Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray, int offset, int length) => ToHexString(inArray, offset, length, "x2"); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(byte[] inArray) => Polyfill.ToHexStringLower(inArray, 0, inArray.Length); /// /// Converts an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(byte[] inArray) => Polyfill.ToHexString(inArray, 0, inArray.Length); /// @@ -54,16 +59,19 @@ static int GetHexValue(char hex) => /// /// Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] FromHexString(ReadOnlySpan chars) => Polyfill.FromHexString(chars.ToString()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexString(ReadOnlySpan bytes) => Polyfill.ToHexString(bytes.ToArray()); /// /// Converts a span of 8-bit unsigned integers to its equivalent string representation that is encoded with lowercase hex characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToHexStringLower(ReadOnlySpan bytes) => Polyfill.ToHexStringLower(bytes.ToArray()); /// diff --git a/src/Split/uap10.0/DateTimeOffsetPolyfill.cs b/src/Split/uap10.0/DateTimeOffsetPolyfill.cs index 6837790e..7bb9a5ad 100644 --- a/src/Split/uap10.0/DateTimeOffsetPolyfill.cs +++ b/src/Split/uap10.0/DateTimeOffsetPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTimeOffset target) @@ -30,32 +31,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out DateTimeOffset result) => DateTimeOffset.TryParse(input.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format, provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) => DateTimeOffset.TryParseExact(input.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/uap10.0/DateTimePolyfill.cs b/src/Split/uap10.0/DateTimePolyfill.cs index 4641f3e5..4d329796 100644 --- a/src/Split/uap10.0/DateTimePolyfill.cs +++ b/src/Split/uap10.0/DateTimePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(DateTime target) @@ -29,32 +30,38 @@ long TicksComponent() /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s, provider, DateTimeStyles.None, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out DateTime result) => DateTime.TryParse(s.ToString(), provider, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out DateTime result) => DateTime.TryParse(s.ToString(), null, DateTimeStyles.None, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParse(s.ToString(), provider, styles, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, string format, IFormatProvider? provider, DateTimeStyles style, out DateTime result) => DateTime.TryParseExact(s.ToString(), format, provider, style, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) => DateTime.TryParseExact(s.ToString(), format.ToString(), provider, styles, out result); #endif diff --git a/src/Split/uap10.0/DelegatePolyfill.cs b/src/Split/uap10.0/DelegatePolyfill.cs index effdb126..59cc5e31 100644 --- a/src/Split/uap10.0/DelegatePolyfill.cs +++ b/src/Split/uap10.0/DelegatePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.ComponentModel; +using System.Runtime.CompilerServices; static partial class Polyfill { /// @@ -39,6 +40,7 @@ public bool MoveNext() /// /// Gets an enumerator for the invocation targets of this delegate. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static InvocationListEnumerator EnumerateInvocationList(TDelegate? target) where TDelegate : Delegate => new(target); diff --git a/src/Split/uap10.0/FilePolyfill.cs b/src/Split/uap10.0/FilePolyfill.cs index 6dda0398..42fd2619 100644 --- a/src/Split/uap10.0/FilePolyfill.cs +++ b/src/Split/uap10.0/FilePolyfill.cs @@ -48,11 +48,13 @@ public static Task AppendAllTextAsync(string path, ReadOnlyMemory contents /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents) => File.AppendAllText(path, contents.ToString()); /// /// Appends the specified string to the file, creating the file if it does not already exist. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void AppendAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.AppendAllText(path, contents.ToString(), encoding); /// @@ -76,12 +78,14 @@ public static async Task WriteAllBytesAsync(string path, ReadOnlyMemory by /// Creates a new file, writes the specified string to the file, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents) => File.WriteAllText(path, contents.ToString()); /// /// Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. /// If the target file already exists, it is truncated and overwritten. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void WriteAllText(string path, ReadOnlySpan contents, Encoding encoding) => File.WriteAllText(path, contents.ToString(), encoding); /// diff --git a/src/Split/uap10.0/GuidPolyfill.cs b/src/Split/uap10.0/GuidPolyfill.cs index 2bd53673..bc6b9129 100644 --- a/src/Split/uap10.0/GuidPolyfill.cs +++ b/src/Split/uap10.0/GuidPolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System.Text; using System; using System.Security.Cryptography; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Guid) @@ -11,9 +12,11 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s, out result); /// Creates a new according to RFC 9562, following the Version 7 format. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid CreateVersion7() => CreateVersion7(DateTimeOffset.UtcNow); /// Creates a new according to RFC 9562, following the Version 7 format. public static Guid CreateVersion7(DateTimeOffset timestamp) @@ -40,26 +43,31 @@ public static Guid CreateVersion7(DateTimeOffset timestamp) /// /// Converts span of characters representing the GUID to the equivalent Guid structure, provided that the string is in the specified format. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParseExact(ReadOnlySpan input, ReadOnlySpan format, out Guid result) => Guid.TryParseExact(input.ToString(), format.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out Guid result) => Guid.TryParse(s.ToString(), out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan input, out Guid result) => Guid.TryParse(input.ToString(), out result); /// /// Tries to parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out Guid result) => Guid.TryParse(Encoding.UTF8.GetString(utf8Text), out result); /// /// Parse a span of UTF-8 bytes into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Guid Parse(ReadOnlySpan utf8Text) => Guid.Parse(Encoding.UTF8.GetString(utf8Text)); #endif diff --git a/src/Split/uap10.0/Lock.cs b/src/Split/uap10.0/Lock.cs index 94fcf1ff..36946028 100644 --- a/src/Split/uap10.0/Lock.cs +++ b/src/Split/uap10.0/Lock.cs @@ -5,6 +5,7 @@ namespace System.Threading; using Diagnostics; using Diagnostics.CodeAnalysis; +using Runtime.CompilerServices; /// /// Provides a way to get mutual exclusion in regions of code between different threads. A lock may be held by one thread at /// a time. @@ -23,26 +24,31 @@ class Lock /// /// Enters the lock. Once the method returns, the calling thread would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enter() => Monitor.Enter(this); /// /// Tries to enter the lock without waiting. If the lock is entered, the calling thread would be the only thread that /// holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter() => Monitor.TryEnter(this); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(TimeSpan timeout) => Monitor.TryEnter(this, timeout); /// /// Tries to enter the lock, waiting for roughly the specified duration. If the lock is entered, the calling thread /// would be the only thread that holds the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEnter(int millisecondsTimeout) => TryEnter(TimeSpan.FromMilliseconds(millisecondsTimeout)); /// /// Exits the lock. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Exit() => Monitor.Exit(this); /// /// Enters the lock and returns a that may be disposed to exit the lock. Once the method returns, diff --git a/src/Split/uap10.0/Numbers/BytePolyfill.cs b/src/Split/uap10.0/Numbers/BytePolyfill.cs index ef3f744e..0ea017af 100644 --- a/src/Split/uap10.0/Numbers/BytePolyfill.cs +++ b/src/Split/uap10.0/Numbers/BytePolyfill.cs @@ -4,6 +4,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -12,37 +13,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out byte result) => byte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its byte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out byte result) => byte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out byte result) => byte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its byte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out byte result) => byte.TryParse(s.ToString(), style, provider, out result); #endif diff --git a/src/Split/uap10.0/Numbers/DoublePolyfill.cs b/src/Split/uap10.0/Numbers/DoublePolyfill.cs index ba5333f6..d903ddfe 100644 --- a/src/Split/uap10.0/Numbers/DoublePolyfill.cs +++ b/src/Split/uap10.0/Numbers/DoublePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out double result) => double.TryParse(s, NumberStyles.Float, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its double-precision floating-point number equivalent.. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out double result) => double.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Float, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out double result) => double.TryParse(s.ToString(), out result); /// /// Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out double result) => double.TryParse(s.ToString(), NumberStyles.Float, provider, out result); #endif diff --git a/src/Split/uap10.0/Numbers/Int16Polyfill.cs b/src/Split/uap10.0/Numbers/Int16Polyfill.cs index 5eb1b384..960cf68c 100644 --- a/src/Split/uap10.0/Numbers/Int16Polyfill.cs +++ b/src/Split/uap10.0/Numbers/Int16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out short result) => short.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its short equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out short result) => short.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out short result) => short.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its short equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out short result) => short.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/uap10.0/Numbers/Int32Polyfill.cs b/src/Split/uap10.0/Numbers/Int32Polyfill.cs index 549ff189..2920eae4 100644 --- a/src/Split/uap10.0/Numbers/Int32Polyfill.cs +++ b/src/Split/uap10.0/Numbers/Int32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out int result) => int.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 32-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out int result) => int.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out int result) => int.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out int result) => int.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/uap10.0/Numbers/Int64Polyfill.cs b/src/Split/uap10.0/Numbers/Int64Polyfill.cs index bd33ce0e..0b7b1b10 100644 --- a/src/Split/uap10.0/Numbers/Int64Polyfill.cs +++ b/src/Split/uap10.0/Numbers/Int64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out long result) => long.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its 64-bit signed integer equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out long result) => long.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out long result) => long.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its 64-bit signed integer equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out long result) => long.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/uap10.0/Numbers/SBytePolyfill.cs b/src/Split/uap10.0/Numbers/SBytePolyfill.cs index 97411565..890452b1 100644 --- a/src/Split/uap10.0/Numbers/SBytePolyfill.cs +++ b/src/Split/uap10.0/Numbers/SBytePolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its sbyte equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out sbyte result) => sbyte.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out sbyte result) => sbyte.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its sbyte equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out sbyte result) => sbyte.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/uap10.0/Numbers/UInt16Polyfill.cs b/src/Split/uap10.0/Numbers/UInt16Polyfill.cs index 34f39f97..ed095880 100644 --- a/src/Split/uap10.0/Numbers/UInt16Polyfill.cs +++ b/src/Split/uap10.0/Numbers/UInt16Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ushort equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ushort result) => ushort.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ushort result) => ushort.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ushort equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ushort result) => ushort.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/uap10.0/Numbers/UInt32Polyfill.cs b/src/Split/uap10.0/Numbers/UInt32Polyfill.cs index 859149be..e11b65c9 100644 --- a/src/Split/uap10.0/Numbers/UInt32Polyfill.cs +++ b/src/Split/uap10.0/Numbers/UInt32Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out uint result) => uint.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its uint equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out uint result) => uint.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out uint result) => uint.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its uint equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out uint result) => uint.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/uap10.0/Numbers/UInt64Polyfill.cs b/src/Split/uap10.0/Numbers/UInt64Polyfill.cs index c14bb347..10122d2b 100644 --- a/src/Split/uap10.0/Numbers/UInt64Polyfill.cs +++ b/src/Split/uap10.0/Numbers/UInt64Polyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.Globalization; +using System.Runtime.CompilerServices; using System.Text; static partial class Polyfill { @@ -11,37 +12,44 @@ static partial class Polyfill /// /// Tries to parse a string into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(string? s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s, NumberStyles.Integer, provider, out result); #if FeatureMemory /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, provider, out result); /// /// Tries to parse a span of UTF-8 characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpanutf8Text, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), style, provider, out result); /// /// Tries to convert a UTF-8 character span containing the string representation of a number to its ulong equivalent. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan utf8Text, out ulong result) => ulong.TryParse(Encoding.UTF8.GetString(utf8Text), NumberStyles.Integer, null, out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, out ulong result) => ulong.TryParse(s.ToString(), out result); /// /// Converts the span representation of a number in a specified style and culture-specific format to its ulong equivalent. A return value indicates whether the conversion succeeded. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), style, provider, out result); /// /// Tries to parse a span of characters into a value. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out ulong result) => ulong.TryParse(s.ToString(), NumberStyles.Integer, provider, out result); #endif diff --git a/src/Split/uap10.0/OperatingSystemPolyfill.cs b/src/Split/uap10.0/OperatingSystemPolyfill.cs index 5d1f8de3..68413c7d 100644 --- a/src/Split/uap10.0/OperatingSystemPolyfill.cs +++ b/src/Split/uap10.0/OperatingSystemPolyfill.cs @@ -3,6 +3,7 @@ #if FeatureRuntimeInformation namespace Polyfills; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; static partial class Polyfill @@ -14,114 +15,135 @@ static bool IsOsVersionAtLeast(int major, int minor = 0, int build = 0, int revi /// /// Indicates whether the current application is running as WASI. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWasi() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("WASI")); /// /// Indicates whether the current application is running on Mac Catalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalyst() => OperatingSystem.IsMacOS() || OperatingSystem.IsIOS(); /// /// Check for the Mac Catalyst version (iOS version as presented in Apple documentation) with a ≤ version comparison. Used to guard APIs that were added in the given Mac Catalyst release. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacCatalystVersionAtLeast(int major, int minor = 0, int build = 0) => IsMacCatalyst() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the macOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified macOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOSVersionAtLeast(int major, int minor = 0, int build = 0) => OperatingSystemCache.IsMacOSVersionAtLeast(major, minor, build); /// /// Checks if the FreeBSD version (returned by the Linux command uname) is greater than or equal to the specified version. /// This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) => OperatingSystemCache.IsFreeBSDVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Android. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroid() => OperatingSystemCache.IsAndroid(); /// /// Checks if the Android version (returned by the Linux command uname) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsAndroidVersionAtLeast(major, minor, build, revision); /// /// Checks if the Windows version (returned by RtlGetVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified Windows version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindowsVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) => OperatingSystemCache.IsWindowsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on the specified platform. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatform(string platform) => RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)); /// /// Checks if the operating system version is greater than or equal to the specified platform version. This method can be used to guard APIs that were added in the specified OS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsOSPlatformVersionAtLeast(string platform, int major, int minor = 0, int build = 0, int revision = 0) => IsOSPlatform(platform) && IsOsVersionAtLeast(major, minor, build, revision); /// /// Indicates whether the current application is running on Windows. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWindows() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Indicates whether the current application is running on macOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMacOS() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); /// /// Indicates whether the current application is running on iOS or MacCatalyst. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")); /// /// Indicates whether the current application is running on Linux. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); /// /// Indicates whether the current application is running on FreeBSD. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsFreeBSD() => RuntimeInformation.OSDescription.ToLower().Contains("freebsd"); /// /// Checks if the iOS/MacCatalyst version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified iOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsIOS() && IsOsVersionAtLeast(major, minor, build); /// /// Checks if the tvOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified tvOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsTvOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running on tvOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsTvOS() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")); /// /// Indicates whether the current application is running on watchOS. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOS() => IsIOS() || RuntimeInformation.OSDescription.ToLower().Contains("watchos"); /// /// Checks if the watchOS version (returned by libobjc.get_operatingSystemVersion) is greater than or equal to the specified version. This method can be used to guard APIs that were added in the specified watchOS version. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWatchOSVersionAtLeast(int major, int minor = 0, int build = 0) => IsWatchOS() && IsOsVersionAtLeast(major, minor, build); /// /// Indicates whether the current application is running as WASM in a browser. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsBrowser() => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); } diff --git a/src/Split/uap10.0/PathPolyfill.cs b/src/Split/uap10.0/PathPolyfill.cs index fb4329ac..fc8009da 100644 --- a/src/Split/uap10.0/PathPolyfill.cs +++ b/src/Split/uap10.0/PathPolyfill.cs @@ -3,6 +3,7 @@ namespace Polyfills; using System; using System.IO; +using System.Runtime.CompilerServices; static partial class Polyfill { extension(Path) @@ -11,41 +12,49 @@ static partial class Polyfill /// /// Returns the directory information for the specified path represented by a character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetDirectoryName(ReadOnlySpan path) => Path.GetDirectoryName(path.ToString()).AsSpan(); /// /// Returns the file name and extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileName(ReadOnlySpan path) => Path.GetFileName(path.ToString()).AsSpan(); /// /// Returns the file name without the extension of a file path that is represented by a read-only character span. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetFileNameWithoutExtension(ReadOnlySpan path) => Path.GetFileNameWithoutExtension(path.ToString()).AsSpan(); /// /// Determines whether the path represented by the specified character span includes a file name extension. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool HasExtension(ReadOnlySpan path) => Path.HasExtension(path.ToString()); /// /// Returns the extension of the given path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan GetExtension(ReadOnlySpan path) => Path.GetExtension(path.ToString()).AsSpan(); /// /// Combines a span of strings into a path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Combine(scoped ReadOnlySpan paths) => Path.Combine(paths.ToArray()); /// /// Returns a value that indicates whether the path, specified as a read-only span, ends in a directory separator. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsInDirectorySeparator (ReadOnlySpan path) => EndsInDirectorySeparator(path.ToString()); /// /// Trims one trailing directory separator beyond the root of the specified path. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan TrimEndingDirectorySeparator(ReadOnlySpan path) => TrimEndingDirectorySeparator(path.ToString()).AsSpan(); #endif