Skip to content

Commit 43e5777

Browse files
committed
Support string analysis in C# generator and source generator
1 parent 0d6ec9c commit 43e5777

File tree

118 files changed

+1576
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+1576
-496
lines changed

Src/FastData.Benchmarks/Benchmarks/AnalyzerBenchmarks.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,18 @@ namespace Genbox.FastData.Benchmarks.Benchmarks;
99
[MemoryDiagnoser]
1010
public class AnalyzerBenchmarks
1111
{
12-
private readonly GPerfAnalyzer _analyzer;
12+
private readonly GPerfAnalyzer<string> _analyzer;
1313
private readonly string[] _data;
1414

1515
public AnalyzerBenchmarks()
1616
{
1717
Random rng = new Random(42);
1818
_data = Enumerable.Range(1, 100).Select(_ => TestHelper.GenerateRandomString(rng, 50)).ToArray();
19-
StringProperties props = DataAnalyzer.GetStringProperties(_data);
2019

21-
_analyzer = new GPerfAnalyzer(_data.Length, props, new GPerfAnalyzerConfig(), new Simulator(), NullLogger<GPerfAnalyzer>.Instance);
20+
StringProperties props = DataAnalyzer.GetStringProperties(_data);
21+
_analyzer = new GPerfAnalyzer<string>(_data.Length, props, new GPerfAnalyzerConfig(), new Simulator<string>(_data.Length), NullLogger<GPerfAnalyzer<string>>.Instance);
2222
}
2323

2424
[Benchmark]
25-
public void GPerfAnalyzer() => _analyzer.GetCandidates(_data, OnCandidateFound);
26-
27-
private static bool OnCandidateFound(Candidate candidate)
28-
{
29-
// Do nothing
30-
return true;
31-
}
25+
public IEnumerable<object> GPerfAnalyzer() => _analyzer.GetCandidates(_data);
3226
}

Src/FastData.Generator.CPlusPlus.Tests/Verify/ConditionalStructure_String_3.verified.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ public:
1212
[[nodiscard]]
1313
static bool contains(const std::string_view value) noexcept
1414
{
15-
if (const size_t len = value.length(); len < 1u || len > 255u)
16-
return false;
15+
1716

1817
if (value == "a" || value == "item" || value == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
1918
return true;

Src/FastData.Generator.CPlusPlus/CPlusPlusCodeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class CPlusPlusCodeGenerator : CodeGenerator
1313
private readonly CPlusPlusCodeGeneratorConfig _cfg;
1414

1515
private CPlusPlusCodeGenerator(CPlusPlusCodeGeneratorConfig cfg, ILanguageDef langDef, IConstantsDef constDef, IEarlyExitDef earlyExitDef, IHashDef hashDef)
16-
: base(langDef, constDef, earlyExitDef, hashDef) => _cfg = cfg;
16+
: base(langDef, constDef, earlyExitDef, hashDef, null) => _cfg = cfg;
1717

1818
public static CPlusPlusCodeGenerator Create(CPlusPlusCodeGeneratorConfig userCfg)
1919
{
@@ -26,7 +26,7 @@ public static CPlusPlusCodeGenerator Create(CPlusPlusCodeGeneratorConfig userCfg
2626
public override string Generate<T>(ReadOnlySpan<T> data, GeneratorConfig<T> genCfg, IContext<T> context)
2727
{
2828
//C++ generator does not support chars outside ASCII
29-
if (genCfg.DataType == DataType.Char && (char)(object)genCfg.Constants.MaxValue! > 127)
29+
if (genCfg.DataType == DataType.Char && (char)(object)genCfg.Constants.MaxValue > 127)
3030
throw new InvalidOperationException("C++ generator does not support chars outside ASCII. Please use a different data type or reduce the max value to 127 or lower.");
3131

3232
return base.Generate(data, genCfg, context);

Src/FastData.Generator.CPlusPlus/Internal/Framework/CPlusPlusHashDef.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Genbox.FastData.Generator.Framework;
12
using Genbox.FastData.Generator.Framework.Interfaces;
23
using Genbox.FastData.Generators;
34
using Genbox.FastData.Generators.Extensions;

Src/FastData.Generator.CSharp.Tests/Verify/ConditionalStructure_String_3.verified.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ internal static class ConditionalStructure_String_3
1111

1212
public static bool Contains(string value)
1313
{
14-
if (value.Length < 1u || value.Length > 255u)
15-
return false;
14+
1615

1716
switch (value)
1817
{

Src/FastData.Generator.CSharp.Tests/Verify/HashSetChainStructure_Byte_3.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal static class HashSetChainStructure_Byte_3
3939
return false;
4040
}
4141

42+
4243
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4344
private static ulong Hash(byte value)
4445
{

Src/FastData.Generator.CSharp.Tests/Verify/HashSetChainStructure_Char_3.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal static class HashSetChainStructure_Char_3
3939
return false;
4040
}
4141

42+
4243
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4344
private static ulong Hash(char value)
4445
{

Src/FastData.Generator.CSharp.Tests/Verify/HashSetChainStructure_Double_4.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal static class HashSetChainStructure_Double_4
3939
return false;
4040
}
4141

42+
4243
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4344
private static ulong Hash(double value)
4445
{

Src/FastData.Generator.CSharp.Tests/Verify/HashSetChainStructure_Double_5_HashZeroOrNaN.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal static class HashSetChainStructure_Double_5_HashZeroOrNaN
3939
return false;
4040
}
4141

42+
4243
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4344
private static ulong Hash(double value)
4445
{

Src/FastData.Generator.CSharp.Tests/Verify/HashSetChainStructure_Int16_5.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal static class HashSetChainStructure_Int16_5
3939
return false;
4040
}
4141

42+
4243
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4344
private static ulong Hash(short value)
4445
{

0 commit comments

Comments
 (0)