Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti committed Dec 5, 2023
1 parent 9cf551b commit 2ff8e5b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
21 changes: 10 additions & 11 deletions src/Visp.Common/PooledDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ namespace Visp.Common;

public static class PooledDictionary
{
public static void ReturnToPool<K, V>(this Dictionary<K, V> it) where K : notnull
=> PooledDictionary<K, V>.Return(it);
public static void ReturnToPool<K, V>(this Dictionary<K, V> it)
where K : notnull => PooledDictionary<K, V>.Return(it);

public static Dictionary<K, V> Get<K, V>() where K : notnull
=> PooledDictionary<K, V>.Get();
public static Dictionary<K, V> Get<K, V>()
where K : notnull => PooledDictionary<K, V>.Get();

public static PooledDisposer<Dictionary<K, V>> GetPooled<K, V>() where K : notnull
=> new(
PooledDictionary<K, V>.Get(),
ReturnToPool
);
public static PooledDisposer<Dictionary<K, V>> GetPooled<K, V>()
where K : notnull => new(PooledDictionary<K, V>.Get(), ReturnToPool);
}

public static class PooledDictionary<K, V>
where K: notnull
where K : notnull
{
internal class PooledDictionaryPolicy : PooledObjectPolicy<Dictionary<K, V>>
{
Expand All @@ -44,7 +41,9 @@ public override bool Return(Dictionary<K, V> obj)
}
}

private static readonly ObjectPool<Dictionary<K, V>> s_pool = new DefaultObjectPool<Dictionary<K, V>>(new PooledDictionaryPolicy());
private static readonly ObjectPool<Dictionary<K, V>> s_pool = new DefaultObjectPool<
Dictionary<K, V>
>(new PooledDictionaryPolicy());

public static Dictionary<K, V> Get() => s_pool.Get();

Expand Down
5 changes: 1 addition & 4 deletions src/Visp.Common/PooledDisposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ namespace Visp.Common;
/// <typeparam name="T">Type of object contained</typeparam>
/// <param name="value">Value</param>
/// <param name="ret">Function to call when disposed</param>
public readonly struct PooledDisposer<T>(
T value,
Action<T> ret
) : IDisposable
public readonly struct PooledDisposer<T>(T value, Action<T> ret) : IDisposable
{
/// <summary>
/// The value
Expand Down
13 changes: 6 additions & 7 deletions src/Visp.Common/PooledList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ namespace Visp.Common;

public static class PooledList
{
public static void ReturnToPool<T>(this List<T> obj) =>
PooledList<T>.Return(obj);
public static void ReturnToPool<T>(this List<T> obj) => PooledList<T>.Return(obj);

public static T[] ToArrayAndReturn<T>(this List<T> s) =>
PooledList<T>.ToArrayAndReturn(s);
public static T[] ToArrayAndReturn<T>(this List<T> s) => PooledList<T>.ToArrayAndReturn(s);

public static ImmutableArray<T> ToImmutableAndReturn<T>(this List<T> s) =>
PooledList<T>.ToImmutableAndReturn(s);

public static List<T> Get<T>() => PooledList<T>.Get();

public static PooledDisposer<List<T>> GetPooled<T>() =>
new(Get<T>(), ReturnToPool);
public static PooledDisposer<List<T>> GetPooled<T>() => new(Get<T>(), ReturnToPool);
}

public static class PooledList<T>
Expand All @@ -46,7 +43,9 @@ public override bool Return(List<T> obj)
}
}

private static readonly ObjectPool<List<T>> s_pool = new DefaultObjectPool<List<T>>(new PooledListPolicy());
private static readonly ObjectPool<List<T>> s_pool = new DefaultObjectPool<List<T>>(
new PooledListPolicy()
);

public static List<T> Get() => s_pool.Get();

Expand Down
4 changes: 2 additions & 2 deletions src/Visp.Compiler/Transforms/SyntaxMacroExpander.fs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ let private evaluatePatterns
| SynConst.Unit -> res.Add(UNIT)
| SynConst.Nil -> res.Add(NIL)
| SynConst.String(s, k, _) -> res.Add(STRING(s, k, ParseHelpers.LexCont.Token()))

()

| SynMacroBody.Symbol sym ->
res.Add(LexHelpers.symbolOrKeyword sym.Text)
| SynMacroBody.Symbol sym -> res.Add(LexHelpers.symbolOrKeyword sym.Text)

use pooled = PooledList.GetPooled<token>()
let res = pooled.Value
Expand Down

0 comments on commit 2ff8e5b

Please sign in to comment.