add:添加Unsafe拓展dll

pull/1/head
zxl 2024-11-12 10:41:41 +08:00
parent f708be6475
commit 31a4376b0a
13 changed files with 168 additions and 36 deletions

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b533858ef4834f9bbf200c45f2508cff
timeCreated: 1731379042

View File

@ -0,0 +1,114 @@
#nullable enable
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace System.Runtime.InteropServices
{
/// <summary>
/// An unsafe class that provides a set of methods to access the underlying data representations of collections.
/// </summary>
public static class CollectionsMarshal
{
private class ListView<T>
{
public T[] _items;
public int _size;
public int _version;
private static readonly T[] s_emptyArray = new T[0];
public void EnsureCapacity(int min)
{
if (this._items.Length >= min)
return;
int num = this._items.Length == 0 ? 4 : this._items.Length * 2;
if ((uint)num > 2146435071U)
num = 2146435071;
if (num < min)
num = min;
this.Capacity = num;
}
public int Capacity
{
get => this._items.Length;
set
{
if (value < this._size)
throw new ArgumentOutOfRangeException(nameof(value), "Capacity is set too small");
if (value == this._items.Length)
return;
if (value > 0)
{
T[] destinationArray = new T[value];
if (this._size > 0)
Array.Copy((Array)this._items, 0, (Array)destinationArray, 0, this._size);
this._items = destinationArray;
}
else
this._items = s_emptyArray;
}
}
}
/// <summary>
/// Get a <see cref="Span{T}"/> view over a <see cref="List{T}"/>'s data.
/// Items should not be added or removed from the <see cref="List{T}"/> while the <see cref="Span{T}"/> is in use.
/// </summary>
/// <param name="list">The list to get the data view over.</param>
/// <typeparam name="T">The type of the elements in the list.</typeparam>
public static Span<T> AsSpan<T>(this List<T>? list)
{
if (list is null)
return default;
var listView = Unsafe.As<ListView<T>>(list);
return listView._items.AsSpan();
}
public static void SetCount<T>(this List<T> list, int count)
{
ForceSetCount(list, count);
}
/// <summary>
/// Sets the count of the <see cref="List{T}"/> to the specified value.
/// </summary>
/// <param name="list">The list to set the count of.</param>
/// <param name="count">The value to set the list's count to.</param>
/// <typeparam name="T">The type of the elements in the list.</typeparam>
/// <exception cref="NullReferenceException">
/// <paramref name="list"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="count"/> is negative.
/// </exception>
/// <remarks>
/// When increasing the count, uninitialized data is being exposed.
/// </remarks>
public static void ForceSetCount<T>(this List<T> list, int count)
{
if (list is null)
throw new NullReferenceException("list is null.");
var listView = Unsafe.As<ListView<T>>(list);
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count), $"{nameof(count)} must be more than 0!");
}
listView._version++;
if (count > list.Capacity)
{
listView.EnsureCapacity(count);
}
else if (count < listView._size && RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
Array.Clear(listView._items, count, listView._size - count);
}
listView._size = count;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a99c6693782341e39d4f1a4f83b12b1a
timeCreated: 1731379093

Binary file not shown.

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5ef328159ce94eec8591720a9bbbf211
timeCreated: 1731379042

Binary file not shown.

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e84d12c68228493193ffd3d1a5e96d2d
timeCreated: 1731379042

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 85cc353531c94c1ea21b23ac3ed21ac9
timeCreated: 1731379042

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e2b5f278e4274744a87e5d249997b009
timeCreated: 1731379042

View File

@ -1,41 +1,41 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask", "UniTask.csproj", "{294e6d56-1b1c-42fb-b926-f2e3316862bc}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hotfix", "Hotfix.csproj", "{e04f01c5-6093-b77a-2de5-556e489fa4f1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.Linq", "UniTask.Linq.csproj", "{0803a435-acbd-0585-3192-448b4a214bc1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-firstpass", "Assembly-CSharp-firstpass.csproj", "{15a8914d-7f3c-94f5-3c3e-d69e1b59eb1f}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniFramework.Utility", "UniFramework.Utility.csproj", "{642f67ee-7892-9ca2-28c6-722173805eb4}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask", "UniTask.csproj", "{294e6d56-1b1c-42fb-b926-f2e3316862bc}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniFramework.Event", "UniFramework.Event.csproj", "{cee0fa50-6857-f04d-f247-66eb24d9a8ca}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.DOTween", "UniTask.DOTween.csproj", "{7c049e19-3f64-2c7c-49e9-36d43077066f}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IngameDebugConsole.Runtime", "IngameDebugConsole.Runtime.csproj", "{1bc74da9-4e3f-e28e-c028-265d90567a1d}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hotfix", "Hotfix.csproj", "{e04f01c5-6093-b77a-2de5-556e489fa4f1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniFramework.Machine", "UniFramework.Machine.csproj", "{ba3dee40-778e-9f57-6b42-b7dceb87a141}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniFramework.Event", "UniFramework.Event.csproj", "{cee0fa50-6857-f04d-f247-66eb24d9a8ca}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Loader", "Unity.Loader.csproj", "{3771f7f8-3d80-281e-54c3-acf9751ee1f7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.TextMeshPro", "UniTask.TextMeshPro.csproj", "{5b7ab77b-e6cf-500d-9fdb-babaa689e8c7}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IngameDebugConsole.Runtime", "IngameDebugConsole.Runtime.csproj", "{1bc74da9-4e3f-e28e-c028-265d90567a1d}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.ThirdParty", "Unity.ThirdParty.csproj", "{043c94ad-22c5-bcf6-a68c-63b97092908a}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniFramework.Utility", "UniFramework.Utility.csproj", "{642f67ee-7892-9ca2-28c6-722173805eb4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.Addressables", "UniTask.Addressables.csproj", "{4920da9d-aeb8-a336-3665-34c8c5a30159}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-Editor", "Assembly-CSharp-Editor.csproj", "{43167fe8-7886-84ab-93d9-fc322b35d48d}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.Editor", "UniTask.Editor.csproj", "{0c19362e-5c9e-a33d-3bc5-d8b54bcd2fbc}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.TextMeshPro", "UniTask.TextMeshPro.csproj", "{5b7ab77b-e6cf-500d-9fdb-babaa689e8c7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-Editor-firstpass", "Assembly-CSharp-Editor-firstpass.csproj", "{ae0c4732-2303-0d45-3c63-becf9c55621f}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IngameDebugConsole.Editor", "IngameDebugConsole.Editor.csproj", "{45edf886-41ef-ca3b-f0bc-eb853a2030e6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{621b7a87-88d5-94bf-0175-a0a301730ca7}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.DOTween", "UniTask.DOTween.csproj", "{7c049e19-3f64-2c7c-49e9-36d43077066f}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp-Editor-firstpass", "Assembly-CSharp-Editor-firstpass.csproj", "{ae0c4732-2303-0d45-3c63-becf9c55621f}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.Editor", "UniTask.Editor.csproj", "{0c19362e-5c9e-a33d-3bc5-d8b54bcd2fbc}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{621b7a87-88d5-94bf-0175-a0a301730ca7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Runtime", "Unity.Runtime.csproj", "{5de1f128-4857-86fc-6490-ecb36b9b3b68}"
EndProject
@ -44,42 +44,42 @@ Global
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{294e6d56-1b1c-42fb-b926-f2e3316862bc}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{294e6d56-1b1c-42fb-b926-f2e3316862bc}.Debug|Any CPU.Build.0 = Debug|Any CPU
{e04f01c5-6093-b77a-2de5-556e489fa4f1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{e04f01c5-6093-b77a-2de5-556e489fa4f1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0803a435-acbd-0585-3192-448b4a214bc1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0803a435-acbd-0585-3192-448b4a214bc1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15a8914d-7f3c-94f5-3c3e-d69e1b59eb1f}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15a8914d-7f3c-94f5-3c3e-d69e1b59eb1f}.Debug|Any CPU.Build.0 = Debug|Any CPU
{642f67ee-7892-9ca2-28c6-722173805eb4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{642f67ee-7892-9ca2-28c6-722173805eb4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{cee0fa50-6857-f04d-f247-66eb24d9a8ca}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{cee0fa50-6857-f04d-f247-66eb24d9a8ca}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7c049e19-3f64-2c7c-49e9-36d43077066f}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7c049e19-3f64-2c7c-49e9-36d43077066f}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1bc74da9-4e3f-e28e-c028-265d90567a1d}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1bc74da9-4e3f-e28e-c028-265d90567a1d}.Debug|Any CPU.Build.0 = Debug|Any CPU
{294e6d56-1b1c-42fb-b926-f2e3316862bc}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{294e6d56-1b1c-42fb-b926-f2e3316862bc}.Debug|Any CPU.Build.0 = Debug|Any CPU
{e04f01c5-6093-b77a-2de5-556e489fa4f1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{e04f01c5-6093-b77a-2de5-556e489fa4f1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ba3dee40-778e-9f57-6b42-b7dceb87a141}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ba3dee40-778e-9f57-6b42-b7dceb87a141}.Debug|Any CPU.Build.0 = Debug|Any CPU
{cee0fa50-6857-f04d-f247-66eb24d9a8ca}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{cee0fa50-6857-f04d-f247-66eb24d9a8ca}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3771f7f8-3d80-281e-54c3-acf9751ee1f7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3771f7f8-3d80-281e-54c3-acf9751ee1f7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5b7ab77b-e6cf-500d-9fdb-babaa689e8c7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5b7ab77b-e6cf-500d-9fdb-babaa689e8c7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1bc74da9-4e3f-e28e-c028-265d90567a1d}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1bc74da9-4e3f-e28e-c028-265d90567a1d}.Debug|Any CPU.Build.0 = Debug|Any CPU
{043c94ad-22c5-bcf6-a68c-63b97092908a}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{043c94ad-22c5-bcf6-a68c-63b97092908a}.Debug|Any CPU.Build.0 = Debug|Any CPU
{642f67ee-7892-9ca2-28c6-722173805eb4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{642f67ee-7892-9ca2-28c6-722173805eb4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4920da9d-aeb8-a336-3665-34c8c5a30159}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4920da9d-aeb8-a336-3665-34c8c5a30159}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43167fe8-7886-84ab-93d9-fc322b35d48d}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43167fe8-7886-84ab-93d9-fc322b35d48d}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0c19362e-5c9e-a33d-3bc5-d8b54bcd2fbc}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0c19362e-5c9e-a33d-3bc5-d8b54bcd2fbc}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45edf886-41ef-ca3b-f0bc-eb853a2030e6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45edf886-41ef-ca3b-f0bc-eb853a2030e6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{621b7a87-88d5-94bf-0175-a0a301730ca7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{621b7a87-88d5-94bf-0175-a0a301730ca7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5b7ab77b-e6cf-500d-9fdb-babaa689e8c7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5b7ab77b-e6cf-500d-9fdb-babaa689e8c7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ae0c4732-2303-0d45-3c63-becf9c55621f}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ae0c4732-2303-0d45-3c63-becf9c55621f}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45edf886-41ef-ca3b-f0bc-eb853a2030e6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45edf886-41ef-ca3b-f0bc-eb853a2030e6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7c049e19-3f64-2c7c-49e9-36d43077066f}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7c049e19-3f64-2c7c-49e9-36d43077066f}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0c19362e-5c9e-a33d-3bc5-d8b54bcd2fbc}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0c19362e-5c9e-a33d-3bc5-d8b54bcd2fbc}.Debug|Any CPU.Build.0 = Debug|Any CPU
{621b7a87-88d5-94bf-0175-a0a301730ca7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{621b7a87-88d5-94bf-0175-a0a301730ca7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5de1f128-4857-86fc-6490-ecb36b9b3b68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5de1f128-4857-86fc-6490-ecb36b9b3b68}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection

View File

@ -1,2 +1,2 @@
m_EditorVersion: 2021.3.22f1c1
m_EditorVersionWithRevision: 2021.3.22f1c1 (99bccbe894f5)
m_EditorVersion: 2022.3.13f1c1
m_EditorVersionWithRevision: 2022.3.13f1c1 (d214d547af8b)