Skip to content

Commit 81a08e2

Browse files
Add in modifier to projection function so that readonly structs won't be copied when applying the projection.
1 parent 8a6b9dd commit 81a08e2

File tree

8 files changed

+11
-10
lines changed

8 files changed

+11
-10
lines changed

src/StructLinq.Benchmark/ArrayClassSum.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ public Container(int element)
5050
Element = element;
5151
}
5252
}
53+
5354
private struct Select : IFunction<Container, int>
5455
{
55-
public int Eval(Container element)
56+
public int Eval(in Container element)
5657
{
5758
return element.Element;
5859
}

src/StructLinq.Benchmark/RangeWhereSelectSum.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ public int SysSum()
6262

6363
struct WherePredicate : IFunction<int, bool>
6464
{
65-
public bool Eval(int element)
65+
public bool Eval(in int element)
6666
{
6767
return (element & 1) == 0;
6868
}
6969
}
7070

7171
struct SelectFunction : IFunction<int, int>
7272
{
73-
public int Eval(int element)
73+
public int Eval(in int element)
7474
{
7575
return element * 2;
7676
}

src/StructLinq.Benchmark/Select.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public int ConvertSelect()
6565

6666
struct MultFunction : IFunction<int, double>
6767
{
68-
public double Eval(int element)
68+
public double Eval(in int element)
6969
{
7070
return element * 2.0;
7171
}

src/StructLinq.Benchmark/Where.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public int ConvertSelect()
6868

6969
struct WhereFunc : IFunction<int, bool>
7070
{
71-
public bool Eval(int element)
71+
public bool Eval(in int element)
7272
{
7373
return element > 0;
7474
}

src/StructLinq.Tests/SelectTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected override IEnumerable<int> Build(int size)
4646

4747
struct MultFunction : IFunction<int, double>
4848
{
49-
public double Eval(int element)
49+
public double Eval(in int element)
5050
{
5151
return element * 2.0;
5252
}

src/StructLinq.Tests/WhereTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void StructTest()
4646

4747
struct WhereFunc : IFunction<int, bool>
4848
{
49-
public bool Eval(int element)
49+
public bool Eval(in int element)
5050
{
5151
return element > 0;
5252
}

src/StructLinq/Functions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public StructFunction(Func<TIn, TOut> inner)
1919
{
2020
this.inner = inner;
2121
}
22-
public TOut Eval(TIn element)
22+
public TOut Eval(in TIn element)
2323
{
2424
return inner(element);
2525
}

src/StructLinq/IFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace StructLinq
22
{
3-
public interface IFunction<in TIn, out TOut>
3+
public interface IFunction<TIn, out TOut>
44
{
5-
TOut Eval(TIn element);
5+
TOut Eval(in TIn element);
66
}
77
}

0 commit comments

Comments
 (0)