Skip to content

Commit

Permalink
Used new C# collection expressions throughout the solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Feb 4, 2024
1 parent afa99d1 commit 91a0191
Show file tree
Hide file tree
Showing 132 changed files with 347 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void TestEnumeratorLinq() {

var values = dict.ToArray();
Asserts.SequenceEqual(
new[] { "string1", "string3", "string5", },
["string1", "string3", "string5"],
values);
}

Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin.Roslyn/src/ReadOnlyTypeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void Execute(GeneratorExecutionContext context) {
}

private GeneratorExecutionContext? context_;
private readonly List<(INamedTypeSymbol, ITypeV2)> queue_ = new();
private readonly List<(INamedTypeSymbol, ITypeV2)> queue_ = [];

public void EnqueueContainer(INamedTypeSymbol symbol, ITypeV2 typeV2) {
// If this assertion fails, then it means that syntax nodes are added
Expand All @@ -112,7 +112,7 @@ public void EnqueueContainer(INamedTypeSymbol symbol, ITypeV2 typeV2) {
this.queue_.Add((symbol, typeV2));
}

private readonly List<(ISymbol, Exception)> errorSymbols_ = new();
private readonly List<(ISymbol, Exception)> errorSymbols_ = [];

public void EnqueueError(ISymbol errorSymbol, Exception exception) {
// If this assertion fails, then it means that syntax nodes are added
Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin.Ui/src/playback/al/AlAudioBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void SetPcm(short[][] channelSamples) {
public void SetMonoPcm(short[] samples) {
this.AudioChannelsType = AudioChannelsType.MONO;
this.LengthInSamples = samples.Length;
this.channels_ = new[] { samples };
this.channels_ = [samples];
}

public void SetStereoPcm(short[] leftChannelSamples,
Expand All @@ -44,7 +44,7 @@ public void SetStereoPcm(short[] leftChannelSamples,

this.AudioChannelsType = AudioChannelsType.STEREO;
this.LengthInSamples = leftChannelSamples.Length;
this.channels_ = new[] { leftChannelSamples, rightChannelSamples };
this.channels_ = [leftChannelSamples, rightChannelSamples];
}

public short GetPcm(AudioChannelType channelType, int sampleOffset)
Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin.Ui/src/playback/al/AlAudioPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ private partial class AlAudioPlayer : IAudioPlayer<short> {
private float volume_ = 1;

private readonly TrackedDisposables<IAudioPlayer<short>>
subAudioPlayers_ = new();
subAudioPlayers_ = [];

private readonly TrackedDisposables<IAudioPlayback<short>> playbacks_ =
new();
[];

public bool IsDisposed { get; private set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace fin.ui.playback.al {
public partial class AlAudioManager {
private class AlJitAudioPlayback : BAlAudioPlayback,
IJitAudioPlayback<short> {
private readonly List<SingleBuffer> allBuffers_ = new();
private readonly List<SingleBuffer> allBuffers_ = [];
private readonly Queue<SingleBuffer> readyForDataBuffers_ = new();
private readonly Dictionary<int, SingleBuffer> buffersById_ = new();

Expand Down
42 changes: 21 additions & 21 deletions FinModelUtility/Fin/Fin.Ui/src/rendering/gl/GlShaderProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ private static
ReferenceCountCacheDictionary<(string vertexSrc, string fragmentSrc),
CachedShaderProgram> programCache_ =
new(vertexAndFragmentSrc => {
var (vertexSrc, fragmentSrc) = vertexAndFragmentSrc;
var vertexShaderId =
GlShaderProgram.vertexShaderCache_.GetAndIncrement(
vertexSrc);
var fragmentShaderId =
GlShaderProgram.fragmentShaderCache_.GetAndIncrement(
fragmentSrc);

var programId = GL.CreateProgram();

GL.AttachShader(programId, vertexShaderId);
GL.AttachShader(programId, fragmentShaderId);
GL.LinkProgram(programId);

return new CachedShaderProgram {
ProgramId = programId,
VertexShaderSource = vertexSrc,
FragmentShaderSource = fragmentSrc,
};
},
var (vertexSrc, fragmentSrc) = vertexAndFragmentSrc;
var vertexShaderId =
GlShaderProgram.vertexShaderCache_.GetAndIncrement(
vertexSrc);
var fragmentShaderId =
GlShaderProgram.fragmentShaderCache_.GetAndIncrement(
fragmentSrc);

var programId = GL.CreateProgram();

GL.AttachShader(programId, vertexShaderId);
GL.AttachShader(programId, fragmentShaderId);
GL.LinkProgram(programId);

return new CachedShaderProgram {
ProgramId = programId,
VertexShaderSource = vertexSrc,
FragmentShaderSource = fragmentSrc,
};
},
(vertexAndFragmentSrc, cachedShaderProgram) => {
GL.DeleteProgram(cachedShaderProgram.ProgramId);

Expand Down Expand Up @@ -95,7 +95,7 @@ private void ReleaseUnmanagedResources_()
private static int CreateAndCompileShader_(string src,
ShaderType shaderType) {
var shaderId = GL.CreateShader(shaderType);
GL.ShaderSource(shaderId, 1, new[] {src}, (int[]) null);
GL.ShaderSource(shaderId, 1, [src], (int[]) null);
GL.CompileShader(shaderId);

// TODO: Throw/return this error
Expand Down
2 changes: 1 addition & 1 deletion FinModelUtility/Fin/Fin.Ui/src/rendering/gl/GlTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class GlTransform {
private static readonly Matrix4x4Stack modelViewMatrix_ = new();
private static readonly Matrix4x4Stack projectionMatrix_ = new();

private static LinkedList<Matrix4x4Stack> currentMatrices_ = new();
private static LinkedList<Matrix4x4Stack> currentMatrices_ = [];

public static Matrix4x4 ModelMatrix {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace fin.ui.rendering.gl.material {
public abstract class BGlMaterialShader<TMaterial> : IGlMaterialShader
where TMaterial : IReadOnlyMaterial {
private LinkedList<CachedTextureUniformData> cachedTextureUniformDatas_ =
new();
[];

private LinkedList<CachedLightUniformData> cachedLightUniformDatas_ = new();
private LinkedList<CachedLightUniformData> cachedLightUniformDatas_ = [];

private readonly IModel model_;
private readonly ILighting? lighting_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ protected override void Setup(
var equations = material.Equations;
for (var i = 0; i < MaterialConstants.MAX_TEXTURES; ++i) {
if (!equations.DoOutputsDependOn(
new[] {
FixedFunctionSource.TEXTURE_COLOR_0 + i,
[
FixedFunctionSource.TEXTURE_COLOR_0 + i,
FixedFunctionSource.TEXTURE_ALPHA_0 + i
})) {
])) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class GlState {
public int ActiveTexture { get; set; }= -1;

public int[] CurrentTextureBindings { get; set; } =
new int[] { -1, -1, -1, -1, -1, -1, -1, -1 };
[-1, -1, -1, -1, -1, -1, -1, -1];
}

public static partial class GlUtil {
Expand Down
2 changes: 1 addition & 1 deletion FinModelUtility/Fin/Fin/src/data/AsyncCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace fin.data {
public class AsyncCollector<T> {
private readonly List<Task<T>> impl_ = new();
private readonly List<Task<T>> impl_ = [];

public void Clear() => this.impl_.Clear();

Expand Down
2 changes: 1 addition & 1 deletion FinModelUtility/Fin/Fin/src/data/counters/CounterArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace fin.data.counters {
public class CounterArray : IFinList<int> {
private readonly List<int> impl_ = new();
private readonly List<int> impl_ = [];

public int Count => this.impl_.Count;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SortedSetDictionary<TKey, TValue>
public void Add(TKey key, TValue value) {
SortedSet<TValue> set;
if (!this.impl_.TryGetValue(key, out set)) {
this.impl_[key] = set = new SortedSet<TValue>();
this.impl_[key] = set = [];
}

set.Add(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace fin.data.disposables {
public class TrackedDisposables<T> : IEnumerable<T>
where T : class, IFinDisposable {
private readonly LinkedList<WeakReference<T>> impl_ = new();
private readonly LinkedList<WeakReference<T>> impl_ = [];

public int Count => this.Count();

Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin/src/data/fuzzy/FuzzyFilterTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class FuzzyFilterTree<T> : IFuzzyFilterTree<T> {
// TODO: Add tests.
// TODO: Add support for different sorting systems.

private readonly List<FuzzyNode> nodes_ = new();
private readonly List<FuzzyNode> nodes_ = [];
private readonly Func<T, IReadOnlySet<string>> nodeToKeywords_;

private readonly IFuzzySearchDictionary<FuzzyNode> impl_ =
Expand All @@ -15,7 +15,7 @@ public class FuzzyFilterTree<T> : IFuzzyFilterTree<T> {
// TODO: Clean this up.
private class FuzzyNode : IFuzzyNode<T> {
private readonly FuzzyFilterTree<T> tree_;
private readonly List<IFuzzyNode<T>> children_ = new();
private readonly List<IFuzzyNode<T>> children_ = [];

public FuzzyNode(FuzzyFilterTree<T> tree) {
this.tree_ = tree;
Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin/src/data/lazy/LazyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace fin.data.lazy {
/// List implementation that lazily populates its entries when accessed.
/// </summary>
public class LazyList<T> : ILazyArray<T> {
private readonly List<T> impl_ = new();
private readonly List<bool> populated_ = new();
private readonly List<T> impl_ = [];
private readonly List<bool> populated_ = [];
private readonly Func<int, T> handler_;

public LazyList(Func<int, T> handler) {
Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin/src/data/nodes/GraphNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public interface IGraphNode<T> : INode<T> {
}

public sealed class GraphNode<T> : IGraphNode<T> {
private readonly OrderedHashSet<IGraphNode<T>> parentNodes_ = new();
private readonly OrderedHashSet<IGraphNode<T>> childNodes_ = new();
private readonly OrderedHashSet<IGraphNode<T>> parentNodes_ = [];
private readonly OrderedHashSet<IGraphNode<T>> childNodes_ = [];

public T Value { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion FinModelUtility/Fin/Fin/src/data/nodes/TreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ IEnumerable<INode<T>> INode<T>.ParentNodes {

public sealed class TreeNode<T> : ITreeNode<T> {
private ITreeNode<T>? parent_;
private readonly OrderedHashSet<ITreeNode<T>> children_ = new();
private readonly OrderedHashSet<ITreeNode<T>> children_ = [];

public T Value { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin/src/data/sets/OrderedHashSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace fin.data.sets {
public class OrderedHashSet<T> : IFinSet<T> {
// TODO: Can this be optimized??
private readonly LinkedList<T> list_ = new();
private readonly HashSet<T> set_ = new();
private readonly LinkedList<T> list_ = [];
private readonly HashSet<T> set_ = [];

public int Count => this.list_.Count;

Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin/src/image/io/tile/Etc1TileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace fin.image.io.tile {
* https://github.com/Gericom/EveryFileExplorer/blob/master/3DS/GPU/Textures.cs
* https://github.com/gdkchan/Ohana3DS-Rebirth/blob/master/Ohana3DS%20Rebirth/Ohana/TextureCodec.cs */

private static readonly int[] ETC1_MODIFIER_TABLES_ = {
private static readonly int[] ETC1_MODIFIER_TABLES_ = [
2, 8, -2, -8,
5, 17, -5, -17,
9, 29, -9, -29,
Expand All @@ -31,7 +31,7 @@ namespace fin.image.io.tile {
24, 80, -24, -80,
33, 106, -33, -106,
47, 183, -47, -183
};
];

public Etc1TileReader(bool hasAlpha) {
this.hasAlpha_ = hasAlpha;
Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin/src/io/FileHierarchy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public IEnumerable<IReadOnlyTreeDirectory> GetAncestry()

private class FileHierarchyDirectory : BFileHierarchyIoObject,
IFileHierarchyDirectory {
private readonly List<IFileHierarchyDirectory> subdirs_ = new();
private readonly List<IFileHierarchyFile> files_ = new();
private readonly List<IFileHierarchyDirectory> subdirs_ = [];
private readonly List<IFileHierarchyFile> files_ = [];

public FileHierarchyDirectory(
IFileHierarchy hierarchy,
Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin/src/io/FileSystemPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public SubdirPaths(string absoluteSubdirPath) {
public IReadOnlyCollection<string> AbsoluteFilePaths => AbsoluteFilePathsImpl;
public IReadOnlyCollection<ISubdirPaths> Subdirs => SubdirsImpl;

public LinkedList<string> AbsoluteFilePathsImpl { get; } = new();
public LinkedList<ISubdirPaths> SubdirsImpl { get; } = new();
public LinkedList<string> AbsoluteFilePathsImpl { get; } = [];
public LinkedList<ISubdirPaths> SubdirsImpl { get; } = [];
}
}
}
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin/src/io/bundles/FileBundleDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public interface IFileBundleDirectory {
}

public class FileBundleDirectory : IFileBundleDirectory {
private readonly List<IFileBundleDirectory> subdirs_ = new();
private readonly List<IAnnotatedFileBundle> fileBundles_ = new();
private readonly List<IFileBundleDirectory> subdirs_ = [];
private readonly List<IAnnotatedFileBundle> fileBundles_ = [];

public FileBundleDirectory(IFileHierarchyDirectory? directory) {
this.Directory = directory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace fin.io.bundles {
public class AnnotatedFileBundleGathererAccumulator : IAnnotatedFileBundleGathererAccumulator {
private readonly List<IAnnotatedFileBundleGatherer> gatherers_ = new();
private readonly List<IAnnotatedFileBundleGatherer> gatherers_ = [];

public IAnnotatedFileBundleGathererAccumulator Add(IAnnotatedFileBundleGatherer gatherer) {
this.gatherers_.Add(gatherer);
Expand All @@ -25,7 +25,7 @@ public class AnnotatedFileBundleGathererAccumulator<TFileBundle>
: IAnnotatedFileBundleGathererAccumulator<TFileBundle>
where TFileBundle : IFileBundle {
private readonly List<IAnnotatedFileBundleGatherer<TFileBundle>>
gatherers_ = new();
gatherers_ = [];

public IAnnotatedFileBundleGathererAccumulator<TFileBundle> Add(
IAnnotatedFileBundleGatherer<TFileBundle> gatherer) {
Expand All @@ -47,7 +47,7 @@ public class AnnotatedFileBundleGathererAccumulatorWithInput<TFileBundle, T>
: IAnnotatedFileBundleGathererAccumulatorWithInput<TFileBundle, T>
where TFileBundle : IFileBundle {
private readonly List<IAnnotatedFileBundleGatherer<TFileBundle>>
gatherers_ = new();
gatherers_ = [];

private readonly T input_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace fin.io.bundles {
public class ParallelAnnotatedFileBundleGathererAccumulator :
IAnnotatedFileBundleGathererAccumulator {
private readonly List<IAnnotatedFileBundleGatherer> gatherers_ = new();
private readonly List<IAnnotatedFileBundleGatherer> gatherers_ = [];

public IAnnotatedFileBundleGathererAccumulator Add(IAnnotatedFileBundleGatherer gatherer) {
this.gatherers_.Add(gatherer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class DirectoryInformation : ISubdirPaths {
public IReadOnlyCollection<string> AbsoluteFilePaths => AbsoluteFilePathsImpl;
public IReadOnlyCollection<ISubdirPaths> Subdirs => SubdirsImpl;

public LinkedList<string> AbsoluteFilePathsImpl { get; } = new();
public LinkedList<DirectoryInformation> SubdirsImpl { get; } = new();
public LinkedList<string> AbsoluteFilePathsImpl { get; } = [];
public LinkedList<DirectoryInformation> SubdirsImpl { get; } = [];
}

public interface IFileLister {
Expand Down
Loading

0 comments on commit 91a0191

Please sign in to comment.