New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System ;
using System.Diagnostics.Contracts ;
using System.Runtime.CompilerServices ;
using System.Runtime.InteropServices ;
using Microsoft.Toolkit.HighPerformance.Enumerables ;
2020-05-13 22:32:20 +03:00
using Microsoft.Toolkit.HighPerformance.Helpers.Internals ;
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
2021-02-09 01:50:06 +03:00
namespace Microsoft.Toolkit.HighPerformance
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
{
/// <summary>
/// Helpers for working with the <see cref="Span{T}"/> type.
/// </summary>
public static class SpanExtensions
{
/// <summary>
/// Returns a reference to the first element within a given <see cref="Span{T}"/>, with no bounds checks.
/// </summary>
/// <typeparam name="T">The type of elements in the input <see cref="Span{T}"/> instance.</typeparam>
/// <param name="span">The input <see cref="Span{T}"/> instance.</param>
/// <returns>A reference to the first element within <paramref name="span"/>.</returns>
/// <remarks>This method doesn't do any bounds checks, therefore it is responsibility of the caller to perform checks in case the returned value is dereferenced.</remarks>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T DangerousGetReference < T > ( this Span < T > span )
{
return ref MemoryMarshal . GetReference ( span ) ;
}
/// <summary>
/// Returns a reference to an element at a specified index within a given <see cref="Span{T}"/>, with no bounds checks.
/// </summary>
/// <typeparam name="T">The type of elements in the input <see cref="Span{T}"/> instance.</typeparam>
/// <param name="span">The input <see cref="Span{T}"/> instance.</param>
/// <param name="i">The index of the element to retrieve within <paramref name="span"/>.</param>
/// <returns>A reference to the element within <paramref name="span"/> at the index specified by <paramref name="i"/>.</returns>
/// <remarks>This method doesn't do any bounds checks, therefore it is responsibility of the caller to ensure the <paramref name="i"/> parameter is valid.</remarks>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T DangerousGetReferenceAt < T > ( this Span < T > span , int i )
{
ref T r0 = ref MemoryMarshal . GetReference ( span ) ;
2020-10-22 02:19:30 +03:00
ref T ri = ref Unsafe . Add ( ref r0 , ( nint ) ( uint ) i ) ;
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
return ref ri ;
}
2020-10-22 02:25:30 +03:00
/// <summary>
/// Returns a reference to an element at a specified index within a given <see cref="Span{T}"/>, with no bounds checks.
/// </summary>
/// <typeparam name="T">The type of elements in the input <see cref="Span{T}"/> instance.</typeparam>
/// <param name="span">The input <see cref="Span{T}"/> instance.</param>
/// <param name="i">The index of the element to retrieve within <paramref name="span"/>.</param>
/// <returns>A reference to the element within <paramref name="span"/> at the index specified by <paramref name="i"/>.</returns>
/// <remarks>This method doesn't do any bounds checks, therefore it is responsibility of the caller to ensure the <paramref name="i"/> parameter is valid.</remarks>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T DangerousGetReferenceAt < T > ( this Span < T > span , nint i )
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
{
ref T r0 = ref MemoryMarshal . GetReference ( span ) ;
ref T ri = ref Unsafe . Add ( ref r0 , i ) ;
return ref ri ;
}
2020-10-17 18:55:54 +03:00
#if SPAN_RUNTIME_SUPPORT
/// <summary>
/// Returns a <see cref="Span2D{T}"/> instance wrapping the underlying data for the given <see cref="Span{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items in the input <see cref="Span{T}"/> instance.</typeparam>
/// <param name="span">The input <see cref="Span{T}"/> instance.</param>
/// <param name="height">The height of the resulting 2D area.</param>
/// <param name="width">The width of each row in the resulting 2D area.</param>
/// <returns>The resulting <see cref="Span2D{T}"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when one of the input parameters is out of range.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown when the requested area is outside of bounds for <paramref name="span"/>.
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span2D < T > AsSpan2D < T > ( this Span < T > span , int height , int width )
{
2020-12-22 15:02:18 +03:00
return new ( span , height , width ) ;
2020-10-17 18:55:54 +03:00
}
/// <summary>
/// Returns a <see cref="Span2D{T}"/> instance wrapping the underlying data for the given <see cref="Span{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items in the input <see cref="Span{T}"/> instance.</typeparam>
/// <param name="span">The input <see cref="Span{T}"/> instance.</param>
/// <param name="offset">The initial offset within <paramref name="span"/>.</param>
/// <param name="height">The height of the resulting 2D area.</param>
/// <param name="width">The width of each row in the resulting 2D area.</param>
/// <param name="pitch">The pitch in the resulting 2D area.</param>
/// <returns>The resulting <see cref="Span2D{T}"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when one of the input parameters is out of range.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown when the requested area is outside of bounds for <paramref name="span"/>.
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span2D < T > AsSpan2D < T > ( this Span < T > span , int offset , int height , int width , int pitch )
{
2020-12-22 15:02:18 +03:00
return new ( span , offset , height , width , pitch ) ;
2020-10-17 18:55:54 +03:00
}
#endif
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
/// <summary>
/// Casts a <see cref="Span{T}"/> of one primitive type <typeparamref name="T"/> to <see cref="Span{T}"/> of bytes.
/// </summary>
2020-05-13 22:32:20 +03:00
/// <typeparam name="T">The type if items in the source <see cref="Span{T}"/>.</typeparam>
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
/// <param name="span">The source slice, of type <typeparamref name="T"/>.</param>
/// <returns>A <see cref="Span{T}"/> of bytes.</returns>
/// <exception cref="OverflowException">
/// Thrown if the <see cref="Span{T}.Length"/> property of the new <see cref="Span{T}"/> would exceed <see cref="int.MaxValue"/>.
/// </exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span < byte > AsBytes < T > ( this Span < T > span )
where T : unmanaged
{
return MemoryMarshal . AsBytes ( span ) ;
}
/// <summary>
/// Casts a <see cref="Span{T}"/> of one primitive type <typeparamref name="TFrom"/> to another primitive type <typeparamref name="TTo"/>.
/// </summary>
/// <typeparam name="TFrom">The type of items in the source <see cref="Span{T}"/>.</typeparam>
/// <typeparam name="TTo">The type of items in the destination <see cref="Span{T}"/>.</typeparam>
/// <param name="span">The source slice, of type <typeparamref name="TFrom"/>.</param>
/// <returns>A <see cref="Span{T}"/> of type <typeparamref name="TTo"/></returns>
/// <remarks>
/// Supported only for platforms that support misaligned memory access or when the memory block is aligned by other means.
/// </remarks>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span < TTo > Cast < TFrom , TTo > ( this Span < TFrom > span )
2020-10-04 16:13:54 +03:00
where TFrom : unmanaged
where TTo : unmanaged
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
{
return MemoryMarshal . Cast < TFrom , TTo > ( span ) ;
}
2020-05-13 22:32:20 +03:00
/// <summary>
/// Gets the index of an element of a given <see cref="Span{T}"/> from its reference.
/// </summary>
/// <typeparam name="T">The type if items in the input <see cref="Span{T}"/>.</typeparam>
/// <param name="span">The input <see cref="Span{T}"/> to calculate the index for.</param>
/// <param name="value">The reference to the target item to get the index for.</param>
/// <returns>The index of <paramref name="value"/> within <paramref name="span"/>.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="value"/> does not belong to <paramref name="span"/>.</exception>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2020-10-28 16:52:03 +03:00
public static int IndexOf < T > ( this Span < T > span , ref T value )
2020-05-13 22:32:20 +03:00
{
ref T r0 = ref MemoryMarshal . GetReference ( span ) ;
IntPtr byteOffset = Unsafe . ByteOffset ( ref r0 , ref value ) ;
2020-10-28 16:52:03 +03:00
nint elementOffset = byteOffset / ( nint ) ( uint ) Unsafe . SizeOf < T > ( ) ;
2020-05-13 22:32:20 +03:00
2020-10-28 16:52:03 +03:00
if ( ( nuint ) elementOffset > = ( uint ) span . Length )
2020-05-13 22:32:20 +03:00
{
2020-10-28 16:52:03 +03:00
ThrowArgumentOutOfRangeExceptionForInvalidReference ( ) ;
2020-05-13 22:32:20 +03:00
}
2020-10-28 16:52:03 +03:00
return ( int ) elementOffset ;
2020-05-13 22:32:20 +03:00
}
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
/// <summary>
/// Counts the number of occurrences of a given value into a target <see cref="Span{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items in the input <see cref="Span{T}"/> instance.</typeparam>
/// <param name="span">The input <see cref="Span{T}"/> instance to read.</param>
/// <param name="value">The <typeparamref name="T"/> value to look for.</param>
/// <returns>The number of occurrences of <paramref name="value"/> in <paramref name="span"/>.</returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Count < T > ( this Span < T > span , T value )
where T : IEquatable < T >
{
2020-05-13 22:32:20 +03:00
ref T r0 = ref MemoryMarshal . GetReference ( span ) ;
2020-10-22 02:19:30 +03:00
nint length = ( nint ) ( uint ) span . Length ;
2020-05-13 22:32:20 +03:00
2020-10-23 04:55:14 +03:00
return ( int ) SpanHelper . Count ( ref r0 , length , value ) ;
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
}
/// <summary>
/// Enumerates the items in the input <see cref="Span{T}"/> instance, as pairs of reference/index values.
/// This extension should be used directly within a <see langword="foreach"/> loop:
/// <code>
/// Span<int> numbers = new[] { 1, 2, 3, 4, 5, 6, 7 };
///
/// foreach (var item in numbers.Enumerate())
/// {
/// // Access the index and value of each item here...
/// int index = item.Index;
/// ref int value = ref item.Value;
/// }
/// </code>
/// The compiler will take care of properly setting up the <see langword="foreach"/> loop with the type returned from this method.
/// </summary>
/// <typeparam name="T">The type of items to enumerate.</typeparam>
/// <param name="span">The source <see cref="Span{T}"/> to enumerate.</param>
/// <returns>A wrapper type that will handle the reference/index enumeration for <paramref name="span"/>.</returns>
/// <remarks>The returned <see cref="SpanEnumerable{T}"/> value shouldn't be used directly: use this extension in a <see langword="foreach"/> loop.</remarks>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SpanEnumerable < T > Enumerate < T > ( this Span < T > span )
{
2020-12-22 15:02:18 +03:00
return new ( span ) ;
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
}
/// <summary>
/// Tokenizes the values in the input <see cref="Span{T}"/> instance using a specified separator.
/// This extension should be used directly within a <see langword="foreach"/> loop:
/// <code>
/// Span<char> text = "Hello, world!".ToCharArray();
///
/// foreach (var token in text.Tokenize(','))
/// {
/// // Access the tokens here...
/// }
/// </code>
/// The compiler will take care of properly setting up the <see langword="foreach"/> loop with the type returned from this method.
/// </summary>
/// <typeparam name="T">The type of items in the <see cref="Span{T}"/> to tokenize.</typeparam>
/// <param name="span">The source <see cref="Span{T}"/> to tokenize.</param>
/// <param name="separator">The separator <typeparamref name="T"/> item to use.</param>
/// <returns>A wrapper type that will handle the tokenization for <paramref name="span"/>.</returns>
/// <remarks>The returned <see cref="SpanTokenizer{T}"/> value shouldn't be used directly: use this extension in a <see langword="foreach"/> loop.</remarks>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static SpanTokenizer < T > Tokenize < T > ( this Span < T > span , T separator )
where T : IEquatable < T >
{
2020-12-22 15:02:18 +03:00
return new ( span , separator ) ;
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
}
/// <summary>
/// Gets a content hash from the input <see cref="Span{T}"/> instance using the Djb2 algorithm.
2020-05-13 22:32:20 +03:00
/// For more info, see the documentation for <see cref="ReadOnlySpanExtensions.GetDjb2HashCode{T}"/>.
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
/// </summary>
/// <typeparam name="T">The type of items in the input <see cref="Span{T}"/> instance.</typeparam>
/// <param name="span">The input <see cref="Span{T}"/> instance.</param>
/// <returns>The Djb2 value for the input <see cref="Span{T}"/> instance.</returns>
/// <remarks>The Djb2 hash is fully deterministic and with no random components.</remarks>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetDjb2HashCode < T > ( this Span < T > span )
where T : notnull
{
2020-05-13 22:32:20 +03:00
ref T r0 = ref MemoryMarshal . GetReference ( span ) ;
2020-10-22 02:19:30 +03:00
nint length = ( nint ) ( uint ) span . Length ;
2020-05-13 22:32:20 +03:00
return SpanHelper . GetDjb2HashCode ( ref r0 , length ) ;
}
2020-10-30 20:24:01 +03:00
/// <summary>
/// Copies the contents of a given <see cref="Span{T}"/> into destination <see cref="RefEnumerable{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items in the input <see cref="Span{T}"/> instance.</typeparam>
/// <param name="span">The input <see cref="Span{T}"/> instance.</param>
/// <param name="destination">The <see cref="RefEnumerable{T}"/> instance to copy items into.</param>
/// <exception cref="ArgumentException">
/// Thrown when the destination <see cref="RefEnumerable{T}"/> is shorter than the source <see cref="Span{T}"/>.
/// </exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CopyTo < T > ( this Span < T > span , RefEnumerable < T > destination )
{
destination . CopyFrom ( span ) ;
}
/// <summary>
/// Attempts to copy the contents of a given <see cref="Span{T}"/> into destination <see cref="RefEnumerable{T}"/> instance.
/// </summary>
/// <typeparam name="T">The type of items in the input <see cref="Span{T}"/> instance.</typeparam>
/// <param name="span">The input <see cref="Span{T}"/> instance.</param>
/// <param name="destination">The <see cref="RefEnumerable{T}"/> instance to copy items into.</param>
/// <returns>Whether or not the operation was successful.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCopyTo < T > ( this Span < T > span , RefEnumerable < T > destination )
{
return destination . TryCopyFrom ( span ) ;
}
2020-05-13 22:32:20 +03:00
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the given reference is out of range.
/// </summary>
internal static void ThrowArgumentOutOfRangeExceptionForInvalidReference ( )
{
throw new ArgumentOutOfRangeException ( "value" , "The input reference does not belong to an element of the input span" ) ;
New Microsoft.Toolkit.HighPerformance package (#3128)
* Code refactoring
* Added StringExtensions tests
* Fixed test method names
* Added ArrayExtensions tests
* Removed MemoryPool<T>.Resize extension
* Added ArrayPoolExtensions tests
* Added SpinLockExtensions tests
* Moved HashCode<T> class to Helpers namespace
* Added ByReference<T> tests
* Changed visibility of one constructor
* Improved ByReference<T> tests
* Added ReadOnlyByReference<T> tests
* Fixed a small build error
* Added new List<T> extensions
* Added List<T> extensions tests
* Fixed a parameter name
* Fixed incorrect XML docs
* Added missing List<T> extension APIs
* Disabled warning
* Removed unnecessary type constraint
* Bug fixes to some List<T> extensions
* Improved some XML docs
* Added List<T>.DangerousAsSpan extension
* Added more unit tests
* Fixed a bug in the List<T>.DangerousAsSpan extension
* Minor tweaks to some docs
* Removed List<T> extensions (too hacky)
* Minor code tweaks (just in case)
* Fixed incorrect API visibility
* Added tests for the HashCode<T> type
* Added .NET Core 3.0 tests for HashCode<T>
* Added ParallelHelper.For tests
* Code refactoring
* Added ParallelHelper.For2D tests
* Fixed empty condition check for 2D loops
* Added ParallelHelper.ForEach in tests
* Added ParallelHelper.ForEach ref tests
* Fixed ParallelHelper.For2D tests
* Improved ParallelHelper.For/2D tests
* Switched HighPerformance tests to shared project
* Renamed HighPerformance.NetCore project
* Moved HighPerformance tests to subfolder
* Fixed incorrect namespaces
* Added empty HighPerformance.UWP test project
* Fixed shared project for UWP test project
* Added missing Unsafe NuGet package to UWP project
* Switched compile tile directives in HighPerformance project
* Added missing file headers
* Minor code refactoring to HashCode<T>
* Minor performance improvements
* Fixed HashCode<T>.Combine API for > int.MaxValue byte sizes
* Improved HashCode<T>.Combine performance on small spans
* Speed improvements in the GetDjb2HashCode<T> API
* Refactored HashCode<T> to facilitate extensions
* Fixed incorrect namespace
* Added HashCodeExtensions class
* Added HashCodeExtensions tests
* Minor code style tweaks
* Added SpanEnumerable<T> type
* Updated T[] and Span<T> Enumerate extensions
* Added SpanExtensions tests
* Fixed an issue in the DJB2 hash method
* Minor code refactoring
* Added EditorBrowsable attributes to enumerator types
* Added MemoryOwner<T> type
* Minor code refactoring
* More code refactoring
* Added MemoryOwner<T> Empty and Length properties
* Added missing header text
* Fixed a refactoring typo
* Added MemoryOwner<T> tests
* Minor code refactoring
* Fixed MemoryOwner<T> XML docs
* Minor optimization to GetDjb2HashCode
* Minor optimization to HashCode<T>.CombineValues
* Minor optimization to Count extension with managed types
* Added a Count test for the managed path
* Added BoolExtensions.ToInt API
* Removed automatically added rules
* Fixed incorrect XML docs
* Added MemoryOwner<T>.DangerousGetReference API
* Added extensions for some MemoryMarshal APIs
* Minor code tweaks
* Added MemoryOwner<T> method
* Added more XML comments
* Fixed an incorrect method prototype
* Code refactoring, added AllocationMode enum
* Added SpanOwner<T> type
* Added SpanOwner<T> tests
* Removed unnecessary check
* Removed unnecessary package reference on .NET Standard 2.1
* Improved tests for ReadOnlySpan<T>.Count
* Fixed a bug in ReadOnlySpan<T>.Count with managed types
* Updated two type constraints
* Minor optimizations to ParallelHelper
* Minor code tweaks
* Removed unnecessary APIs
* Added UInt32Extensions class
* Added unit tests for the UInt32Extensions class
* Fixed some comments
* Added some remarks to the new uint APIs
* Minor optimization
* Added UInt64Extensions class
* Added unit tests for UInt64Extensions type
* Fixed some typos and comments
* Fixed a unit test
* Minor performance improvements
* Added ToString() override and debug display to MemoryOwner<T>
* Added ToString() override and debug display to SpanOwner<T>
* Added MemoryOwner<T> debug proxy type
* Added SpanOwner<T> debug proxy type
* Added missing using directive
* Added info to the .csproj file
* Removed two APIs, for additional safety
* Refactored bit helpers into a separate class, added by ref overloads
* Minor code tweaks
* Added Box<T> type
* Added tests for the Box<T> type
* Added Box<T> object schema
* Added Box<T>.GetFrom(object) API
* Added more Box<T> tests, added more comments
* Fixed a copy paste fail
* Added ValueTypeExtensions type
* Added ValueTypeExtensions tests
* Added missing GC.SuppressFinalize call in MemoryOwner<T>
* Initial implementation of MemoryStream
* Implemented MemoryStream.Seek method
* Implemented ReadByte and WriteByte methods
* Added Memory<T> extension to create a Stream
* Implemented MemoryStream.Dispose method
* Fixed typos in a test class
* Added ReadAsync overrides
* Added WriteAsync overrides
* Code refactoring
* Added more .NET Standard 2.1 overrides
* Moved CopyToAsync method to .NET Standard 2.0
* Moved FlushAsync, reordered methods
* Added [ReadOnly]Memory<T> extension tests
* Added initial stream tests
* Fixed a bug in MemoryStream.Read
* Added unit tests for the MemoryStream type
* Added MemoryStream.[Read|Write]Byte tests, minor tweaks
* Updated .sln file
* Added IMemoryOwnerStream type
* Added IMemoryOwnerExtensions.AsStream type
* Minor tweaks to some XML comments
* Added IMemoryOwner extensions and stream tests
* Fixed an incorrect namespace
* Aadded ArrayPoolBufferWriter<T> type
* Minor code refactoring
* Added debug view and ToString override for ArrayPoolBufferWriter<T>
* Minor code refactoring
* Added destructor to ArrayPoolBufferWriter<T> type
* Added tests for ArrayPoolBufferWriter<T>
* Fixed some copy-paste fails
* Added IMemoryOwner<T> interface to ArrayPoolBufferWriter<T>
* Updated .csproj description
* Fixed some comments
* Updated sln
* Minor code style tweak
* Minor optimization, code style tweaks
* Fixed some tests not running on .NET Core 3.0
* Added initial Array2DExtensions type
* Added T[,].AsSpan extension
* Added Count<T> and Djb2 hashcode extensions for T[,] arrays
* Added tests for the 2D array extensions
* Code refactoring
* Added NullableByReference<T> type
* Minor code refactoring
* Added NullableReadOnlyByReference<T> type
* Added unit tests for new Nullable[ReadOnly]ByReference<T> types
* Fixed an XML comment
* Added T[,] array GetRow and GetColumn extensions
* Added Array2DColumnEnumerable<T>.ToArray() helper method
* Code refactoring
* Added T[,].GetRow support on .NET Standard 2.0
* Added and optimized T[,].Fill extension
* Added T[,].Fill tests
* Added tests for T[,].GetRow extension
* Bug fixes in the 2D array enumerators
* Added tests for T[,].GetColumn extension
* Fixed a typo
* Fixed duplicate using directives
* Fixed an XML comment
* Inverted precompiler conditional directive for clarity
* Fixed error in an XML comment
* Removed unnecessary using directive
* Fixed publisher name in UWP test project
* Added StyleCop.Analyzers package to UWP test project
* Resolved StyleCop warnings in unit tests
* Added StyleCop.Analyzers package to .NET Core test project
* Resolved .NET Core specific StyleCop warnings
* Updated Test SDK and packages in .NET Core unit test project
* Fixed object name in MemoryStream.ThrowObjectDisposedException()
* Minor code style tweak and optimization
* Added test for the argument name in ParallelHelper exceptions
* Fixed visibility modifiers
* Fixed Box<T> type on ARM devices
* Added MemoryStream tests for argument names in exceptions
* Minor improvements to some unit tests
* Removed duplicate System.Runtime.CompilerServices.Unsafe reference
* Removed unnecessary StyleCop reference and .ruleset file
* Resolved StyleCop warnings in unit tests
* Minor performance improvements in ByReference<T> types on x64
* Minor style tweaks
* Fixed missed refactoring
* Code refactoring
* Added missing readonly struct modifiers
* Enabgled running HighPerformance tests on build.
(cherry picked from commit c5524125391ca208586d0de09fffb89e3a01264d)
* Bug fixes in the Box<T> type on some runtimes
* Added missing "Pack" target in UWP test project
* Code refactoring, moved Box<T> extensions to same file for clarity
* Bumped System.Runtime.CompilerServices.Unsafe to 5.0.0-preview.2.20160.6
* Fixed Box<T>.ToString/GetHashCode issues on .NET Core 2.1 Release
* Updated comments on the Box<T>.GetReference() method
Also pushing this commit just to re-trigger the CI build, since GitHub went offline and caused the previous one to fail/half midway through
* Fixed package downgrade in UWP test project
* Aligned ref returns for ReadOnlySpan<T>/string to MemoryMarsha.GetReference
* Renamed ByReference<T> APIs
* Removed unnecessary preview package
Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
2020-05-06 02:44:11 +03:00
}
}
2021-02-14 11:32:05 +03:00
}