Replaced AsReadOnly property getters with regular properties

Should reduce allocations
This commit is contained in:
Diogo Trindade committed 2021-09-04 19:41:59 +01:00
1 parent 7ad7eaad89
commit 0b370f261c
21 files changed
+84 -42

No files matched your search

@@ -17,13 +17,14 @@ namespace Artemis.Core.LayerBrushes
protected LayerBrushProvider()
{
_layerBrushDescriptors = new List<LayerBrushDescriptor>();
LayerBrushDescriptors = new(_layerBrushDescriptors);
Disabled += OnDisabled;
}
/// <summary>
/// A read-only collection of all layer brushes added with <see cref="RegisterLayerBrushDescriptor{T}" />
/// </summary>
public ReadOnlyCollection<LayerBrushDescriptor> LayerBrushDescriptors => _layerBrushDescriptors.AsReadOnly();
public ReadOnlyCollection<LayerBrushDescriptor> LayerBrushDescriptors { get; }
/// <summary>
/// Registers a layer brush descriptor for a given layer brush, so that it appears in the UI.
@@ -18,13 +18,14 @@ namespace Artemis.Core.LayerEffects
protected LayerEffectProvider()
{
_layerEffectDescriptors = new List<LayerEffectDescriptor>();
LayerEffectDescriptors = new(_layerEffectDescriptors);
Disabled += OnDisabled;
}
/// <summary>
/// A read-only collection of all layer effects added with <see cref="RegisterLayerEffectDescriptor{T}" />
/// </summary>
public ReadOnlyCollection<LayerEffectDescriptor> LayerEffectDescriptors => _layerEffectDescriptors.AsReadOnly();
public ReadOnlyCollection<LayerEffectDescriptor> LayerEffectDescriptors { get; }
/// <summary>
/// Adds a layer effect descriptor for a given layer effect, so that it appears in the UI.
@@ -26,6 +26,9 @@ namespace Artemis.Core.Modules
// These are both set right after construction to keep the constructor of inherited classes clean
Module = null!;
DataModelDescription = null!;
ActivePaths = new(_activePaths);
DynamicChildren = new(_dynamicChildren);
}
/// <summary>
@@ -52,13 +55,13 @@ namespace Artemis.Core.Modules
/// Gets an read-only dictionary of all dynamic children
/// </summary>
[DataModelIgnore]
public ReadOnlyDictionary<string, DynamicChild> DynamicChildren => new(_dynamicChildren);
public ReadOnlyDictionary<string, DynamicChild> DynamicChildren { get; }
/// <summary>
/// Gets a read-only list of <see cref="DataModelPath" />s targeting this data model
/// </summary>
[DataModelIgnore]
public ReadOnlyCollection<DataModelPath> ActivePaths => _activePaths.AsReadOnly();
public ReadOnlyCollection<DataModelPath> ActivePaths { get; }
/// <summary>
/// Returns a read-only collection of all properties in this datamodel that are to be ignored
+8 -2
View File
@@ -114,6 +114,12 @@ namespace Artemis.Core.Modules
private readonly List<(DefaultCategoryName, string)> _defaultProfilePaths = new();
private readonly List<(DefaultCategoryName, string)> _pendingDefaultProfilePaths = new();
public Module()
{
DefaultProfilePaths = new ReadOnlyCollection<(DefaultCategoryName, string)>(_defaultProfilePaths);
HiddenProperties = new(HiddenPropertiesList);
}
/// <summary>
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
@@ -122,7 +128,7 @@ namespace Artemis.Core.Modules
/// <summary>
/// Gets a read only collection of default profile paths
/// </summary>
public IReadOnlyCollection<(DefaultCategoryName, string)> DefaultProfilePaths => _defaultProfilePaths.AsReadOnly();
public IReadOnlyCollection<(DefaultCategoryName, string)> DefaultProfilePaths { get; }
/// <summary>
/// A list of activation requirements
@@ -176,7 +182,7 @@ namespace Artemis.Core.Modules
/// <summary>
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly();
public ReadOnlyCollection<PropertyInfo> HiddenProperties { get; }
internal DataModel? InternalDataModel { get; set; }
+5 -2
View File
@@ -30,6 +30,9 @@ namespace Artemis.Core
_features = new List<PluginFeatureInfo>();
_profilers = new List<Profiler>();
Features = new(_features);
Profilers = new(_profilers);
}
/// <summary>
@@ -64,12 +67,12 @@ namespace Artemis.Core
/// <summary>
/// Gets a read-only collection of all features this plugin provides
/// </summary>
public ReadOnlyCollection<PluginFeatureInfo> Features => _features.AsReadOnly();
public ReadOnlyCollection<PluginFeatureInfo> Features { get; }
/// <summary>
/// Gets a read-only collection of profiles running on the plugin
/// </summary>
public ReadOnlyCollection<Profiler> Profilers => _profilers.AsReadOnly();
public ReadOnlyCollection<Profiler> Profilers { get; }
/// <summary>
/// The assembly the plugin code lives in
@@ -44,6 +44,11 @@ namespace Artemis.Core.ScriptingProviders
/// </summary>
public abstract class ScriptingProvider : PluginFeature
{
protected ScriptingProvider()
{
Scripts = new(InternalScripts);
}
/// <summary>
/// Gets the name of the scripting language this provider provides
/// </summary>
@@ -52,7 +57,7 @@ namespace Artemis.Core.ScriptingProviders
/// <summary>
/// Gets a list of all active scripts belonging to this scripting provider
/// </summary>
public ReadOnlyCollection<Script> Scripts => InternalScripts.AsReadOnly();
public ReadOnlyCollection<Script> Scripts { get; }
internal abstract Type GlobalScriptType { get; }
internal abstract Type ProfileScriptType { get; }