Skip to content

Commit fcce5d0

Browse files
austinv900MrBlue
authored andcommitted
Refactor array and object pooling
1 parent 50d47c6 commit fcce5d0

12 files changed

Lines changed: 16 additions & 340 deletions

File tree

src/ArrayPool.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ namespace Oxide.Core
55
{
66
public static class ArrayPool
77
{
8-
private static readonly IArrayPoolProvider<object> pool;
8+
private static IArrayPool<object> Pool { get; }
99

1010
static ArrayPool()
1111
{
12-
pool = Interface.Oxide.PoolFactory.GetArrayProvider<object>();
12+
Pool = ArrayPool<object>.Shared;
1313
}
1414

15-
[Obsolete("Use Interface.Oxide.PoolFactory")]
16-
public static object[] Get(int length) => pool.Take(length);
15+
[Obsolete("Use ArrayPool<T>.Shared")]
16+
public static object[] Get(int length) => Pool.Take(length);
1717

18-
[Obsolete("Use Interface.Oxide.PoolFactory")]
19-
public static void Free(object[] array) => pool.Return(array);
18+
[Obsolete("Use ArrayPool<T>.Shared")]
19+
public static void Free(object[] array) => Pool.Return(array);
2020
}
2121
}

src/Interface.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public static class Interface
1818
/// </summary>
1919
public static NativeDebugCallback DebugCallback { get; set; }
2020

21-
private static IArrayPoolProvider<object> HookArrays { get; }
21+
private static IArrayPool<object> HookArrays { get; }
2222

2323
static Interface()
2424
{
2525
Oxide = new OxideMod();
26-
HookArrays = Oxide.PoolFactory.GetArrayProvider<object>();
26+
HookArrays = ArrayPool<object>.Shared;
2727
}
2828

2929
/// <summary>

src/Libraries/Covalence/Formatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public class Formatter
129129
[ElementType.Color] = c => new Tag($"[c/{RGBAtoRGB(c)}:", "]")
130130
};
131131

132-
private static readonly IPoolProvider<StringBuilder> stringPool = Interface.Oxide.PoolFactory.GetProvider<StringBuilder>();
132+
private static readonly IPool<StringBuilder> stringPool = PoolFactory<StringBuilder>.Shared;
133133

134134
private class Token : Poolable<Token>
135135
{

src/Oxide.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</PropertyGroup>
1919
<ItemGroup>
2020
<PackageReference Include="Lib.Harmony" Version="2.3.1.1" />
21-
<PackageReference Include="Oxide.Common" Version="2.0.*" />
21+
<PackageReference Include="Oxide.Common" Version="2.0.37-develop" />
2222
<PackageReference Include="Oxide.References" Version="2.0.*">
2323
<PrivateAssets>contentfiles;analyzers;build</PrivateAssets>
2424
</PackageReference>

src/OxideMod.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public sealed class OxideMod
4242
/// </summary>
4343
public static readonly string Branch = Assembly.GetExecutingAssembly().Metadata("GitBranch").FirstOrDefault() ?? "unknown";
4444

45-
/// <summary>
46-
/// Retrieve pooled objects
47-
/// </summary>
48-
public IPoolFactory PoolFactory { get; }
49-
5045
/// <summary>
5146
/// Gets the main logger
5247
/// </summary>
@@ -122,8 +117,6 @@ public sealed class OxideMod
122117
public OxideMod()
123118
{
124119
init_called = false;
125-
CorePoolFactory factory = new CorePoolFactory();
126-
PoolFactory = factory;
127120
}
128121

129122
/// <summary>

src/Plugins/CSPlugin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ protected Harmony HarmonyInstance
7676
/// <summary>
7777
/// Pool of <see cref="object"/> array's
7878
/// </summary>
79-
protected IArrayPoolProvider<object> ObjectArrayPool { get; }
79+
protected IArrayPool<object> ObjectArrayPool { get; }
8080

8181
/// <summary>
8282
/// Initializes a new instance of the CSPlugin class
8383
/// </summary>
8484
public CSPlugin()
8585
{
86-
ObjectArrayPool = Interface.Oxide.PoolFactory.GetArrayProvider<object>();
86+
ObjectArrayPool = ArrayPool<object>.Shared;
8787

8888
// Find all hooks in the plugin and any base classes derived from CSPlugin
8989
Type type = GetType();

src/Plugins/PluginManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public HookSubscriptions()
7979
// Re-usable conflict list used for hook calls
8080
private readonly List<string> hookConflicts = new List<string>();
8181

82-
private IArrayPoolProvider<object> ObjectPool { get; }
82+
private IArrayPool<object> ObjectPool { get; }
8383

8484
/// <summary>
8585
/// Initializes a new instance of the PluginManager class
8686
/// </summary>
8787
public PluginManager(Logger logger)
8888
{
8989
// Initialize
90-
ObjectPool = Interface.Oxide.PoolFactory.GetArrayProvider<object>();
90+
ObjectPool = ArrayPool<object>.Shared;
9191
loadedPlugins = new Dictionary<string, Plugin>();
9292
hookSubscriptions = new Dictionary<string, HookSubscriptions>();
9393
Logger = logger;

src/Plugins/Watchers/FSWatcher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private class QueuedChange
3939
private Timer timers;
4040

4141
private Dictionary<string, FileSystemWatcher> m_symlinkWatchers = new Dictionary<string, FileSystemWatcher>();
42-
private IPoolProvider<StringBuilder> StringPool { get; }
42+
private IPool<StringBuilder> StringPool { get; }
4343

4444
/// <summary>
4545
/// Initializes a new instance of the FSWatcher class
@@ -48,7 +48,7 @@ private class QueuedChange
4848
/// <param name="filter"></param>
4949
public FSWatcher(string directory, string filter)
5050
{
51-
StringPool = Interface.Oxide.PoolFactory.GetProvider<StringBuilder>();
51+
StringPool = PoolFactory<StringBuilder>.Shared;
5252
watchedPlugins = new HashSet<string>();
5353
changeQueue = new Dictionary<string, QueuedChange>();
5454
timers = Interface.Oxide.GetLibrary<Timer>();

src/Pooling/BaseArrayPoolProvider.cs

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/Pooling/BasePoolProvider.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)