Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.Predicates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,17 @@ bool IsIncludedFileOrLocation(Cursor cursor, CXFile file, CXSourceLocation locat
// Use case insensitive comparison on Windows
var equalityComparer = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal;

// Normalize paths to be '/' for comparison
var fileName = file.Name.ToString().NormalizePath();
// Normalize paths to be '/' for comparison. The same file recurs for
// every cursor it contains, so cache the normalized names per file to
// avoid re-allocating them (and re-running Path.GetFullPath) each call.
if (!_fileNames.TryGetValue(file, out var names))
{
var name = file.Name.ToString().NormalizePath();
names = (name, name.NormalizeFullPath());
_fileNames.Add(file, names);
}

var fileName = names.Name;

if (_visitedFiles.Add(fileName) && _config.LogVisitedFiles)
{
Expand All @@ -322,7 +331,7 @@ bool IsIncludedFileOrLocation(Cursor cursor, CXFile file, CXSourceLocation locat
{
return true;
}
else if (_config.TraversalNames.Contains(fileName.NormalizeFullPath(), equalityComparer))
else if (_config.TraversalNames.Contains(names.FullName, equalityComparer))
{
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public sealed partial class PInvokeGenerator : IDisposable
private readonly Dictionary<string, HashSet<string>> _topLevelClassUsings;
private readonly Dictionary<string, List<string>> _topLevelClassAttributes;
private readonly Dictionary<CXFile, (nuint Address, nuint Length)> _fileContents;
private readonly Dictionary<CXFile, (string Name, string FullName)> _fileNames;
private readonly HashSet<string> _topLevelClassNames;
private readonly HashSet<string> _usedRemappings;
private readonly string _placeholderMacroType;
Expand Down Expand Up @@ -161,6 +162,7 @@ public PInvokeGenerator(PInvokeGeneratorConfiguration config, Func<string, Strea
_topLevelClassNames = new HashSet<string>(StringComparer.Ordinal);
_topLevelClassAttributes = new Dictionary<string, List<string>>(StringComparer.Ordinal);
_fileContents = [];
_fileNames = [];
_topLevelClassUsings = new Dictionary<string, HashSet<string>>(StringComparer.Ordinal);
_usedRemappings = new HashSet<string>(StringComparer.Ordinal);
_filePath = "";
Expand Down Expand Up @@ -1680,6 +1682,7 @@ public void GenerateBindings(TranslationUnit translationUnit, string filePath, s
_overloadIndices.Clear();
_isExcluded.Clear();
_fileContents.Clear();
_fileNames.Clear();

if (translationUnit.Handle.NumDiagnostics != 0)
{
Expand Down
Loading