Added pools, IndexedFishMap, IndexedFishSet, fixed bugs related to FishTable.Remove, added Preview.png, various smaller additions, some refactoring too
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2023 bradson
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FisheryLib.Pools;
|
||||
|
||||
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
|
||||
[InterpolatedStringHandler]
|
||||
public record struct PooledStringBuilderHandler : IDisposable
|
||||
{
|
||||
private PooledIList<List<char>> _chars;
|
||||
|
||||
public PooledStringBuilderHandler(int literalLength, int formattedCount)
|
||||
{
|
||||
_chars = new();
|
||||
_chars.List.EnsureCapacity(literalLength + (formattedCount * 8));
|
||||
}
|
||||
|
||||
public void AppendLiteral(string s) => _chars.List.Add(s);
|
||||
|
||||
public void AppendFormatted<T>(T t)
|
||||
{
|
||||
if (t != null)
|
||||
_chars.List.Add(t.ToString());
|
||||
}
|
||||
|
||||
public StringBuilder AppendToStringBuilder(StringBuilder destination)
|
||||
{
|
||||
destination.Append(_chars.List);
|
||||
Dispose();
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void Dispose() => _chars.Dispose();
|
||||
}
|
||||
Reference in New Issue
Block a user