Skip to content

Commit 3edf080

Browse files
committed
Remove data from contexts if it is just the same format
1 parent 3e52156 commit 3edf080

26 files changed

Lines changed: 40 additions & 71 deletions

Src/FastData.Generator.CPlusPlus/Internal/Generators/BinarySearchCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ internal sealed class BinarySearchCode<T>(BinarySearchContext<T> ctx) : CPlusPlu
88
{
99
public override string Generate(ReadOnlySpan<T> data) =>
1010
$$"""
11-
{{FieldModifier}}std::array<{{TypeName}}, {{ctx.Data.Length.ToStringInvariant()}}> entries = {
12-
{{FormatColumns(ctx.Data, ToValueLabel)}}
11+
{{FieldModifier}}std::array<{{TypeName}}, {{data.Length.ToStringInvariant()}}> entries = {
12+
{{FormatColumns(data, ToValueLabel)}}
1313
};
1414
1515
public:
@@ -19,7 +19,7 @@ public override string Generate(ReadOnlySpan<T> data) =>
1919
{{EarlyExits}}
2020
2121
{{ArraySizeType}} lo = 0;
22-
{{ArraySizeType}} hi = {{(ctx.Data.Length - 1).ToStringInvariant()}};
22+
{{ArraySizeType}} hi = {{(data.Length - 1).ToStringInvariant()}};
2323
while (lo <= hi)
2424
{
2525
const size_t mid = lo + ((hi - lo) >> 1);

Src/FastData.Generator.CPlusPlus/Internal/Generators/EytzingerSearchCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ internal sealed class EytzingerSearchCode<T>(EytzingerSearchContext<T> ctx) : CP
88
{
99
public override string Generate(ReadOnlySpan<T> data) =>
1010
$$"""
11-
{{FieldModifier}}std::array<{{TypeName}}, {{ctx.Data.Length.ToStringInvariant()}}> entries = {
12-
{{FormatColumns(ctx.Data, ToValueLabel)}}
11+
{{FieldModifier}}std::array<{{TypeName}}, {{data.Length.ToStringInvariant()}}> entries = {
12+
{{FormatColumns(data, ToValueLabel)}}
1313
};
1414
1515
public:

Src/FastData.Generator.CSharp/Internal/Generators/BinarySearchCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal sealed class BinarySearchCode<T>(BinarySearchContext<T> ctx, CSharpCode
99
public override string Generate(ReadOnlySpan<T> data) =>
1010
$$"""
1111
{{FieldModifier}}{{TypeName}}[] _entries = new {{TypeName}}[] {
12-
{{FormatColumns(ctx.Data, ToValueLabel)}}
12+
{{FormatColumns(data, ToValueLabel)}}
1313
};
1414
1515
{{MethodAttribute}}
@@ -18,7 +18,7 @@ public override string Generate(ReadOnlySpan<T> data) =>
1818
{{EarlyExits}}
1919
2020
int lo = 0;
21-
int hi = {{(ctx.Data.Length - 1).ToStringInvariant()}};
21+
int hi = {{(data.Length - 1).ToStringInvariant()}};
2222
while (lo <= hi)
2323
{
2424
int i = lo + ((hi - lo) >> 1);

Src/FastData.Generator.CSharp/Internal/Generators/EytzingerSearchCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal sealed class EytzingerSearchCode<T>(EytzingerSearchContext<T> ctx, CSha
88
public override string Generate(ReadOnlySpan<T> data) =>
99
$$"""
1010
{{FieldModifier}}{{TypeName}}[] _entries = new {{TypeName}}[] {
11-
{{FormatColumns(ctx.Data, ToValueLabel)}}
11+
{{FormatColumns(data, ToValueLabel)}}
1212
};
1313
1414
{{MethodAttribute}}

Src/FastData.Generator.Rust/Internal/Generators/BinarySearchCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ internal sealed class BinarySearchCode<T>(BinarySearchContext<T> ctx) : RustOutp
88
{
99
public override string Generate(ReadOnlySpan<T> data) =>
1010
$$"""
11-
{{FieldModifier}}const ENTRIES: [{{TypeNameWithLifetime}}; {{ctx.Data.Length.ToStringInvariant()}}] = [
12-
{{FormatColumns(ctx.Data, ToValueLabel)}}
11+
{{FieldModifier}}const ENTRIES: [{{TypeNameWithLifetime}}; {{data.Length.ToStringInvariant()}}] = [
12+
{{FormatColumns(data, ToValueLabel)}}
1313
];
1414
1515
{{MethodAttribute}}
1616
{{MethodModifier}}fn contains(value: {{TypeName}}) -> bool {
1717
{{EarlyExits}}
1818
1919
let mut lo: usize = 0;
20-
let mut hi: usize = {{(ctx.Data.Length - 1).ToStringInvariant()}};
20+
let mut hi: usize = {{(data.Length - 1).ToStringInvariant()}};
2121
while lo <= hi {
2222
let i = lo + ((hi - lo) >> 1);
2323
let entry = Self::ENTRIES[i];

Src/FastData.Generator.Rust/Internal/Generators/EytzingerSearchCode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ internal sealed class EytzingerSearchCode<T>(EytzingerSearchContext<T> ctx) : Ru
77
{
88
public override string Generate(ReadOnlySpan<T> data) =>
99
$$"""
10-
{{FieldModifier}}const ENTRIES: [{{TypeName}}; {{ctx.Data.Length}}] = [
11-
{{FormatColumns(ctx.Data, ToValueLabel)}}
10+
{{FieldModifier}}const ENTRIES: [{{TypeName}}; {{data.Length}}] = [
11+
{{FormatColumns(data, ToValueLabel)}}
1212
];
1313
1414
{{MethodAttribute}}

Src/FastData.InternalShared/Helpers/TestHelper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Security.Cryptography;
33
using System.Text;
44
using Genbox.FastData.Enums;
5+
using Genbox.FastData.Generator.Extensions;
56
using Genbox.FastData.Generators;
67
using Genbox.FastData.Generators.Abstracts;
78
using Genbox.FastData.Internal.Abstracts;
@@ -122,11 +123,12 @@ private static GeneratorSpec Generate<T, TContext>(Func<string, ICodeGenerator>
122123
_ => StructureType.Auto
123124
};
124125

125-
TContext context = structure.Create(vector.Values);
126+
ReadOnlySpan<T> values = vector.Values.AsReadOnlySpan();
127+
TContext context = structure.Create(ref values);
126128
ICodeGenerator generator = func(vector.Identifier);
127129

128130
GeneratorConfig<T> genCfg = new GeneratorConfig<T>(structureType, FastDataGenerator.DefaultStringComparison, props);
129-
string source = generator.Generate(vector.Values, genCfg, context);
131+
string source = generator.Generate(values, genCfg, context);
130132
return new GeneratorSpec(vector.Identifier, source);
131133
}
132134
}

Src/FastData.Testbed/Tests/GPerfTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void ProduceOutputs(string path)
4747

4848
HashData hashData = HashData.Create(data, DataType.String, 1);
4949
HashSetPerfectStructure<string> structure = new HashSetPerfectStructure<string>(hashData);
50-
structure.Create(data);
50+
structure.Create(ref data);
5151
}
5252
}
5353

Src/FastData.Tests/Verify/BinarySearch_Double_3.verified.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,5 @@
44
0.0,
55
1.7976931348623157E+308
66
],
7-
"Context": {
8-
"Data": [
9-
-1.7976931348623157E+308,
10-
0.0,
11-
1.7976931348623157E+308
12-
]
13-
}
7+
"Context": {}
148
}

Src/FastData.Tests/Verify/BinarySearch_Int32_3.verified.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,5 @@
44
0,
55
2147483647
66
],
7-
"Context": {
8-
"Data": [
9-
-2147483648,
10-
0,
11-
2147483647
12-
]
13-
}
7+
"Context": {}
148
}

0 commit comments

Comments
 (0)