forked from AvaloniaUI/Avalonia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy pooled collections to Avalonia.Base project.
- Loading branch information
1 parent
29b7d2e
commit c04b08a
Showing
9 changed files
with
3,036 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace Avalonia.Collections.Pooled | ||
{ | ||
/// <summary> | ||
/// This enum allows control over how data is treated when internal | ||
/// arrays are returned to the ArrayPool. Be careful to understand | ||
/// what each option does before using anything other than the default | ||
/// of Auto. | ||
/// </summary> | ||
public enum ClearMode | ||
{ | ||
/// <summary> | ||
/// <para><code>Auto</code> has different behavior depending on the host project's target framework.</para> | ||
/// <para>.NET Core 2.1: Reference types and value types that contain reference types are cleared | ||
/// when the internal arrays are returned to the pool. Value types that do not contain reference | ||
/// types are not cleared when returned to the pool.</para> | ||
/// <para>.NET Standard 2.0: All user types are cleared before returning to the pool, in case they | ||
/// contain reference types. | ||
/// For .NET Standard, Auto and Always have the same behavior.</para> | ||
/// </summary> | ||
Auto = 0, | ||
/// <summary> | ||
/// The <para><code>Always</code> setting has the effect of always clearing user types before returning to the pool. | ||
/// This is the default behavior on .NET Standard.</para><para>You might want to turn this on in a .NET Core project | ||
/// if you were concerned about sensitive data stored in value types leaking to other pars of your application.</para> | ||
/// </summary> | ||
Always = 1, | ||
/// <summary> | ||
/// <para><code>Never</code> will cause pooled collections to never clear user types before returning them to the pool.</para> | ||
/// <para>You might want to use this setting in a .NET Standard project when you know that a particular collection stores | ||
/// only value types and you want the performance benefit of not taking time to reset array items to their default value.</para> | ||
/// <para>Be careful with this setting: if used for a collection that contains reference types, or value types that contain | ||
/// reference types, this setting could cause memory issues by making the garbage collector unable to clean up instances | ||
/// that are still being referenced by arrays sitting in the ArrayPool.</para> | ||
/// </summary> | ||
Never = 2 | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Avalonia.Base/Collections/Pooled/ICollectionDebugView.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// 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.Collections.Generic; | ||
using System.Diagnostics; | ||
|
||
namespace Avalonia.Collections.Pooled | ||
{ | ||
internal sealed class ICollectionDebugView<T> | ||
{ | ||
private readonly ICollection<T> _collection; | ||
|
||
public ICollectionDebugView(ICollection<T> collection) | ||
{ | ||
_collection = collection ?? throw new ArgumentNullException(nameof(collection)); | ||
} | ||
|
||
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] | ||
public T[] Items | ||
{ | ||
get | ||
{ | ||
T[] items = new T[_collection.Count]; | ||
_collection.CopyTo(items, 0); | ||
return items; | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Avalonia.Base/Collections/Pooled/IReadOnlyPooledList.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Avalonia.Collections.Pooled | ||
{ | ||
/// <summary> | ||
/// Represents a read-only collection of pooled elements that can be accessed by index | ||
/// </summary> | ||
/// <typeparam name="T">The type of elements in the read-only pooled list.</typeparam> | ||
|
||
public interface IReadOnlyPooledList<T> : IReadOnlyList<T> | ||
{ | ||
/// <summary> | ||
/// Gets a <see cref="System.ReadOnlySpan{T}"/> for the items currently in the collection. | ||
/// </summary> | ||
ReadOnlySpan<T> Span { get; } | ||
} | ||
} |
Oops, something went wrong.