Skip to content

Commit 1f2fff4

Browse files
Merge pull request #619 from tannergooding/main
Reduce allocations and improve throughput
2 parents 4d4e062 + f72aae4 commit 1f2fff4

File tree

209 files changed

+1888
-2164
lines changed

Some content is hidden

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

209 files changed

+1888
-2164
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ dotnet_style_qualification_for_method = false:error
244244
dotnet_style_qualification_for_property = false:error
245245

246246
dotnet_style_readonly_field = true:error
247-
dotnet_style_require_accessibility_modifiers = always:error
247+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:error
248248

249249
###############################################################################
250250
# Set dotnet style options to:

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.100",
3+
"version": "10.0.100-preview",
44
"allowPrerelease": true,
55
"rollForward": "latestFeature"
66
}

scripts/build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ try {
172172
$DotNetInstallDirectory = Join-Path -Path $ArtifactsDir -ChildPath "dotnet"
173173
Create-Directory -Path $DotNetInstallDirectory
174174

175-
& $DotNetInstallScript -Channel 8.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
175+
& $DotNetInstallScript -Channel 10.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
176176

177177
$env:PATH="$DotNetInstallDirectory;$env:PATH"
178178
}

scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ if [[ ! -z "$architecture" ]]; then
204204
DotNetInstallDirectory="$ArtifactsDir/dotnet"
205205
CreateDirectory "$DotNetInstallDirectory"
206206

207-
. "$DotNetInstallScript" --channel 8.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
207+
. "$DotNetInstallScript" --channel 10.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
208208

209209
PATH="$DotNetInstallDirectory:$PATH:"
210210
fi

sources/ClangSharp.Interop/ClangSharp.Interop.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFrameworks>net8.0</TargetFrameworks>
5+
<TargetFrameworks>net10.0</TargetFrameworks>
66
</PropertyGroup>
77

88
<PropertyGroup>

sources/ClangSharp.Interop/Extensions/CXCursor.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public readonly string AttrKindSpelling
3737
Debug.Assert(CX_AttrKind_FirstTypeAttr == CX_AttrKind_AddressSpace);
3838
Debug.Assert(CX_AttrKind_LastTypeAttr == CX_AttrKind_WebAssemblyFuncref);
3939

40-
Debug.Assert(CX_AttrKind_FirstStmtAttr == CX_AttrKind_CodeAlign);
40+
Debug.Assert(CX_AttrKind_FirstStmtAttr == CX_AttrKind_CXXAssume);
4141
Debug.Assert(CX_AttrKind_LastStmtAttr == CX_AttrKind_Unlikely);
4242

4343
Debug.Assert(CX_AttrKind_FirstDeclOrStmtAttr == CX_AttrKind_AlwaysInline);
@@ -49,14 +49,14 @@ public readonly string AttrKindSpelling
4949
Debug.Assert(CX_AttrKind_FirstDeclOrTypeAttr == CX_AttrKind_AArch64SVEPcs);
5050
Debug.Assert(CX_AttrKind_LastDeclOrTypeAttr == CX_AttrKind_VectorCall);
5151

52-
Debug.Assert(CX_AttrKind_FirstInheritableParamAttr == CX_AttrKind_SwiftAsyncContext);
52+
Debug.Assert(CX_AttrKind_FirstInheritableParamAttr == CX_AttrKind_Annotate);
5353
Debug.Assert(CX_AttrKind_LastInheritableParamAttr == CX_AttrKind_UseHandle);
5454

55-
Debug.Assert(CX_AttrKind_FirstParameterABIAttr == CX_AttrKind_SwiftAsyncContext);
55+
Debug.Assert(CX_AttrKind_FirstParameterABIAttr == CX_AttrKind_HLSLParamModifier);
5656
Debug.Assert(CX_AttrKind_LastParameterABIAttr == CX_AttrKind_SwiftIndirectResult);
5757

58-
Debug.Assert(CX_AttrKind_FirstHLSLAnnotationAttr == CX_AttrKind_HLSLSV_DispatchThreadID);
59-
Debug.Assert(CX_AttrKind_LastHLSLAnnotationAttr == CX_AttrKind_HLSLSV_GroupIndex);
58+
Debug.Assert(CX_AttrKind_FirstHLSLAnnotationAttr == CX_AttrKind_HLSLPackOffset);
59+
Debug.Assert(CX_AttrKind_LastHLSLAnnotationAttr == CX_AttrKind_HLSLSV_GroupThreadID);
6060

6161
return AttrKind switch {
6262
CX_AttrKind_Invalid => "Invalid",
@@ -1353,7 +1353,7 @@ public readonly string StmtClassSpelling
13531353
Debug.Assert(CX_StmtClass_LastSwitchCase == CX_StmtClass_CaseStmt);
13541354

13551355
Debug.Assert(CX_StmtClass_FirstOMPLoopTransformationDirective == CX_StmtClass_OMPUnrollDirective);
1356-
Debug.Assert(CX_StmtClass_LastOMPLoopTransformationDirective == CX_StmtClass_OMPTileDirective);
1356+
Debug.Assert(CX_StmtClass_LastOMPLoopTransformationDirective == CX_StmtClass_OMPInterchangeDirective);
13571357

13581358
Debug.Assert(CX_StmtClass_FirstOMPLoopDirective == CX_StmtClass_OMPTeamsGenericLoopDirective);
13591359
Debug.Assert(CX_StmtClass_LastOMPLoopDirective == CX_StmtClass_OMPDistributeDirective);
@@ -1362,7 +1362,7 @@ public readonly string StmtClassSpelling
13621362
Debug.Assert(CX_StmtClass_LastOMPLoopBasedDirective == CX_StmtClass_OMPDistributeDirective);
13631363

13641364
Debug.Assert(CX_StmtClass_FirstOMPExecutableDirective == CX_StmtClass_OMPTeamsDirective);
1365-
Debug.Assert(CX_StmtClass_LastOMPExecutableDirective == CX_StmtClass_OMPAtomicDirective);
1365+
Debug.Assert(CX_StmtClass_LastOMPExecutableDirective == CX_StmtClass_OMPAssumeDirective);
13661366

13671367
Debug.Assert(CX_StmtClass_FirstAsmStmt == CX_StmtClass_MSAsmStmt);
13681368
Debug.Assert(CX_StmtClass_LastAsmStmt == CX_StmtClass_GCCAsmStmt);

sources/ClangSharp.Interop/Extensions/CXUnsavedFile.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,41 @@ public static CXUnsavedFile Create(string filename, string contents)
4646
};
4747
}
4848

49+
public static CXUnsavedFile Create(string filename, CXTranslationUnit translationUnit, CXFile baseFile, string additionalContents)
50+
{
51+
sbyte* pFilename, pContents;
52+
nuint contentsLength;
53+
54+
if (string.IsNullOrEmpty(filename))
55+
{
56+
pFilename = null;
57+
}
58+
else
59+
{
60+
var maxFilenameLength = Encoding.UTF8.GetMaxByteCount(filename.Length);
61+
pFilename = (sbyte*)NativeMemory.Alloc((uint)maxFilenameLength + 1);
62+
var filenameLength = (uint)Encoding.UTF8.GetBytes(filename, new Span<byte>(pFilename, maxFilenameLength));
63+
pFilename[filenameLength] = 0;
64+
}
65+
66+
var baseFileContents = translationUnit.GetFileContents(baseFile, out _);
67+
var maxContentsLength = baseFileContents.Length + Encoding.UTF8.GetMaxByteCount((additionalContents?.Length).GetValueOrDefault());
68+
69+
pContents = (sbyte*)NativeMemory.Alloc((uint)maxContentsLength + 1);
70+
71+
var contents = new Span<byte>(pContents, maxContentsLength);
72+
baseFileContents.CopyTo(contents);
73+
74+
contentsLength = (uint)(baseFileContents.Length + Encoding.UTF8.GetBytes(additionalContents, contents[baseFileContents.Length..]));
75+
pContents[contentsLength] = 0;
76+
77+
return new CXUnsavedFile() {
78+
Filename = pFilename,
79+
Contents = pContents,
80+
Length = contentsLength
81+
};
82+
}
83+
4984
public void Dispose()
5085
{
5186
if (Filename != null)

sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ internal sealed partial class CSharpOutputBuilder(string name, PInvokeGenerator
1818
private readonly PInvokeGenerator _generator = generator;
1919
private readonly List<string> _contents = [];
2020
private readonly StringBuilder _currentLine = new StringBuilder();
21-
private readonly SortedSet<string> _usingDirectives = [];
22-
private readonly SortedSet<string> _staticUsingDirectives = [];
21+
private readonly SortedSet<string> _usingDirectives = new SortedSet<string>(StringComparer.Ordinal);
22+
private readonly SortedSet<string> _staticUsingDirectives = new SortedSet<string>(StringComparer.Ordinal);
2323
private readonly string _indentationString = indentationString;
2424
private readonly bool _isTestOutput = isTestOutput;
2525

@@ -80,6 +80,8 @@ public void WriteBlockEnd()
8080

8181
public void Write<T>(T value) => _ = _currentLine.Append(value);
8282

83+
public void Write(ReadOnlySpan<char> value) => _ = _currentLine.Append(value);
84+
8385
public void WriteIndentation()
8486
{
8587
WriteNewlineIfNeeded();

sources/ClangSharp.PInvokeGenerator/ClangSharp.PInvokeGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<PropertyGroup>
55
<RootNamespace>ClangSharp</RootNamespace>
6-
<TargetFrameworks>net8.0</TargetFrameworks>
6+
<TargetFrameworks>net10.0</TargetFrameworks>
77
</PropertyGroup>
88

99
<PropertyGroup>

sources/ClangSharp.PInvokeGenerator/OutputBuilderFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ClangSharp;
1212
internal sealed class OutputBuilderFactory(PInvokeGenerator generator)
1313
{
1414
private readonly bool _writeSourceLocation = generator.Config.GenerateSourceLocationAttribute;
15-
private readonly Dictionary<string, IOutputBuilder> _outputBuilders = [];
15+
private readonly Dictionary<string, IOutputBuilder> _outputBuilders = new Dictionary<string, IOutputBuilder>(StringComparer.Ordinal);
1616

1717
public IEnumerable<IOutputBuilder> OutputBuilders => _outputBuilders.Values;
1818

0 commit comments

Comments
 (0)