Skip to content

Commit

Permalink
Buffer improvements (#76)
Browse files Browse the repository at this point in the history
* 🏇 Allow writing spans to buffers directly

* 📿 Add enumerable composite pipeline constructor

* 🐛
  • Loading branch information
paulcscharf authored Mar 13, 2024
1 parent 881a614 commit a997673
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Bearded.Graphics/Core/BufferStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public void Add(T item0, T item1, T item2, T item3)
IsDirty = true;
}

public void Add(T[] items)
public void Add(ReadOnlySpan<T> items)
{
var newCount = Count + items.Length;
ensureCapacity(newCount);
Array.Copy(items, 0, data, Count, items.Length);
items.CopyTo(data.AsSpan(Count));
Count = newCount;
IsDirty = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Bearded.Graphics/Pipelines/Pipeline.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static partial class Pipeline
{
public static IPipeline<TState> Then<TState>(this IPipeline<TState> basePipeline, IPipeline<TState> continuation)
{
return new Composite<TState>(basePipeline, continuation);
return new Composite<TState>([basePipeline, continuation]);
}

public static IPipeline<TStateOuter> Elevate<TStateInner, TStateOuter>(
Expand Down
6 changes: 6 additions & 0 deletions Bearded.Graphics/Pipelines/Pipeline.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using Bearded.Graphics.Pipelines.Steps;

namespace Bearded.Graphics.Pipelines
Expand All @@ -18,5 +19,10 @@ public static IPipeline<TState> InOrder(params IPipeline<TState>[] steps)
{
return new Composite<TState>(steps);
}

public static IPipeline<TState> InOrder(IEnumerable<IPipeline<TState>> steps)
{
return new Composite<TState>(steps);
}
}
}
9 changes: 2 additions & 7 deletions Bearded.Graphics/Pipelines/Steps/Composite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@

namespace Bearded.Graphics.Pipelines.Steps
{
sealed class Composite<TState> : IPipeline<TState>
sealed class Composite<TState>(IEnumerable<IPipeline<TState>> steps) : IPipeline<TState>
{
private bool flattened;
private ImmutableArray<IPipeline<TState>> steps;

public Composite(params IPipeline<TState>[] steps)
{
this.steps = steps.ToImmutableArray();
}
private ImmutableArray<IPipeline<TState>> steps = steps.ToImmutableArray();

public void Execute(TState state)
{
Expand Down

0 comments on commit a997673

Please sign in to comment.