From a2accaf9a069a7a208277bd649ba0f6d294d6942 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Sat, 30 Nov 2024 12:02:26 +0300 Subject: [PATCH] A bit refactoring pools related stuff and bumping up a version --- src/vm/util/refc_list.cs | 26 +++++++++++++------------- src/vm/util/val_list_adapter.cs | 20 +++++++++----------- src/vm/version.cs | 2 +- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/vm/util/refc_list.cs b/src/vm/util/refc_list.cs index 583904c6..1518a3c1 100644 --- a/src/vm/util/refc_list.cs +++ b/src/vm/util/refc_list.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; namespace bhl { @@ -13,22 +14,21 @@ public class RefcList : List, IValRefcounted, IDisposable public int refs => _refs; - static class PoolHolder - { - [ThreadStatic] - static public Pool> _pool; - public static Pool> pool { - get { - if(_pool == null) - _pool = new Pool>(); - return _pool; - } - } - } + + [ThreadStatic] + static Pool> _pool; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static Pool> GetPool() + { + if(_pool == null) + _pool = new Pool>(); + return _pool; + } static public RefcList New() { - var pool = PoolHolder.pool; + var pool = GetPool(); RefcList list = null; if(pool.stack.Count == 0) diff --git a/src/vm/util/val_list_adapter.cs b/src/vm/util/val_list_adapter.cs index 409dbe40..8908305a 100644 --- a/src/vm/util/val_list_adapter.cs +++ b/src/vm/util/val_list_adapter.cs @@ -24,22 +24,20 @@ public class ValList : IList, IValRefcounted, IDisposable public int refs => _refs; - static class PoolHolder + [ThreadStatic] + static Pool> _pool; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static Pool> GetPool() { - [ThreadStatic] - static public Pool> _pool; - public static Pool> pool { - get { - if(_pool == null) - _pool = new Pool>(); - return _pool; - } - } + if(_pool == null) + _pool = new Pool>(); + return _pool; } static public ValList New(ValList lst, Func val2native) { - var pool = PoolHolder.pool; + var pool = GetPool(); ValList vls = null; if(pool.stack.Count == 0) diff --git a/src/vm/version.cs b/src/vm/version.cs index d6fe8104..9118ecdf 100644 --- a/src/vm/version.cs +++ b/src/vm/version.cs @@ -2,7 +2,7 @@ namespace bhl { public static class Version { - public static string Name = "v2.0.0-beta193"; + public static string Name = "v2.0.0-beta194"; } }