Skip to content

Commit

Permalink
Remove a few unused things.
Browse files Browse the repository at this point in the history
Cache attributes.
  • Loading branch information
wasabii committed Jan 23, 2025
1 parent efb056f commit 1249672
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 75 deletions.
31 changes: 5 additions & 26 deletions src/IKVM.CoreLib/Symbols/IAssemblySymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ interface IAssemblySymbol : ISymbol, ICustomAttributeSymbolProvider
/// </summary>
string? FullName { get; }

/// <summary>
/// Gets a string representing the version of the common language runtime (CLR) saved in the file containing the manifest.
/// </summary>
string ImageRuntimeVersion { get; }

/// <summary>
/// Gets the module that contains the manifest for the current assembly.
/// </summary>
Expand Down Expand Up @@ -78,42 +73,26 @@ interface IAssemblySymbol : ISymbol, ICustomAttributeSymbolProvider
/// <returns></returns>
AssemblyName GetName();

/// <summary>
/// Gets an <see cref="AssemblyName"/> for this assembly, setting the codebase as specified by <paramref name="copiedName"/>.
/// </summary>
/// <param name="copiedName"></param>
/// <returns></returns>
AssemblyName GetName(bool copiedName);

/// <summary>
/// Gets the <see cref="AssemblyName"/> objects for all the assemblies referenced by this assembly.
/// </summary>
/// <returns></returns>
AssemblyName[] GetReferencedAssemblies();
ImmutableArray<AssemblyName> GetReferencedAssemblies();

/// <summary>
/// Gets the <see cref="Type"/> object with the specified name in the assembly instance and optionally throws an exception if the type is not found.
/// Gets the <see cref="ITypeSymbol"/> object with the specified name in the assembly instance.
/// </summary>
/// <param name="name"></param>
/// <param name="throwOnError"></param>
/// <returns></returns>
ITypeSymbol? GetType(string name, bool throwOnError);
ITypeSymbol? GetType(string name);

/// <summary>
/// Gets the <see cref="Type"/> object with the specified name in the assembly instance, with the options of ignoring the case, and of throwing an exception if the type is not found.
/// Gets the <see cref="ITypeSymbol"/> object with the specified name in the assembly instance and optionally throws an exception if the type is not found.
/// </summary>
/// <param name="name"></param>
/// <param name="throwOnError"></param>
/// <param name="ignoreCase"></param>
/// <returns></returns>
ITypeSymbol? GetType(string name, bool throwOnError, bool ignoreCase);

/// <summary>
/// Gets the <see cref="Type"/> object with the specified name in the assembly instance.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
ITypeSymbol? GetType(string name);
ITypeSymbol? GetType(string name, bool throwOnError);

/// <summary>
/// Gets all types defined in this assembly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class IkvmReflectionAssemblySymbol : IkvmReflectionSymbol, IAssemblySymbol
readonly ConditionalWeakTable<Module, IkvmReflectionModuleSymbol> _modules = new();

System.Reflection.AssemblyName? _assemblyName;
ImmutableArray<CustomAttributeSymbol> _customAttributes = default;

/// <summary>
/// Initializes a new instance.
Expand All @@ -45,20 +46,18 @@ internal IkvmReflectionModuleSymbol GetOrCreateModuleSymbol(Module module)

internal Assembly UnderlyingAssembly => _underlyingAssembly;

public IEnumerable<ITypeSymbol> DefinedTypes => ResolveTypeSymbols(_underlyingAssembly.DefinedTypes);

public IMethodSymbol? EntryPoint => _underlyingAssembly.EntryPoint is { } m ? ResolveMethodSymbol(m) : null;

public IEnumerable<ITypeSymbol> ExportedTypes => ResolveTypeSymbols(_underlyingAssembly.ExportedTypes);

public string? FullName => _underlyingAssembly.FullName;

public string ImageRuntimeVersion => _underlyingAssembly.ImageRuntimeVersion;

public IModuleSymbol ManifestModule => ResolveModuleSymbol(_underlyingAssembly.ManifestModule);

public IEnumerable<IModuleSymbol> Modules => ResolveModuleSymbols(_underlyingAssembly.Modules);

public IEnumerable<ITypeSymbol> DefinedTypes => ResolveTypeSymbols(_underlyingAssembly.DefinedTypes);

public IEnumerable<ITypeSymbol> ExportedTypes => ResolveTypeSymbols(_underlyingAssembly.ExportedTypes);

public IMethodSymbol? EntryPoint => _underlyingAssembly.EntryPoint is { } m ? ResolveMethodSymbol(m) : null;

public override bool IsMissing => _underlyingAssembly.__IsMissing;

public ITypeSymbol[] GetExportedTypes()
Expand Down Expand Up @@ -101,34 +100,24 @@ public System.Reflection.AssemblyName GetName()
return _assemblyName ??= ToName(_underlyingAssembly.GetName());
}

public System.Reflection.AssemblyName GetName(bool copiedName)
public ImmutableArray<System.Reflection.AssemblyName> GetReferencedAssemblies()
{
return ToName(_underlyingAssembly.GetName());
}

public System.Reflection.AssemblyName[] GetReferencedAssemblies()
{
var l = _underlyingAssembly.GetReferencedAssemblies();
var a = new System.Reflection.AssemblyName[l.Length];
var l = _underlyingAssembly.GetReferencedAssemblies().ToImmutableArray();
var a = ImmutableArray.CreateBuilder<System.Reflection.AssemblyName>(l.Length);
for (int i = 0; i < l.Length; i++)
a[i] = ToName(l[i]);

return a;
}
a.Add(ToName(l[i]));

public ITypeSymbol? GetType(string name, bool throwOnError)
{
return _underlyingAssembly.GetType(name, throwOnError) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
return a.DrainToImmutable();
}

public ITypeSymbol? GetType(string name, bool throwOnError, bool ignoreCase)
public ITypeSymbol? GetType(string name)
{
return _underlyingAssembly.GetType(name, throwOnError, ignoreCase) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
return _underlyingAssembly.GetType(name) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
}

public ITypeSymbol? GetType(string name)
public ITypeSymbol? GetType(string name, bool throwOnError)
{
return _underlyingAssembly.GetType(name) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
return _underlyingAssembly.GetType(name, throwOnError) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
}

public ITypeSymbol[] GetTypes()
Expand All @@ -138,7 +127,7 @@ public ITypeSymbol[] GetTypes()

public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes()
{
return ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData());
return _customAttributes.IsDefault ? _customAttributes = ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData()) : _customAttributes;
}

public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes(ITypeSymbol attributeType)
Expand Down
32 changes: 11 additions & 21 deletions src/IKVM.CoreLib/Symbols/Reflection/ReflectionAssemblySymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ class ReflectionAssemblySymbol : ReflectionSymbol, IAssemblySymbol
readonly Assembly _underlyingAssembly;
readonly ConditionalWeakTable<Module, ReflectionModuleSymbol> _modules = new();

ImmutableArray<CustomAttributeSymbol> _customAttributes = default;

/// <summary>
/// Initializes a new instance.
/// </summary>
/// <param name="context"></param>
/// <param name="assembly"></param>
public ReflectionAssemblySymbol(ReflectionSymbolContext context, Assembly assembly) :
/// <param name="underlyingAssembly"></param>
public ReflectionAssemblySymbol(ReflectionSymbolContext context, Assembly underlyingAssembly) :
base(context)
{
_underlyingAssembly = assembly ?? throw new ArgumentNullException(nameof(assembly));
_underlyingAssembly = underlyingAssembly ?? throw new ArgumentNullException(nameof(underlyingAssembly));
}

internal Assembly UnderlyingAssembly => _underlyingAssembly;
Expand All @@ -48,8 +50,6 @@ internal ReflectionModuleSymbol GetOrCreateModuleSymbol(Module module)

public string? FullName => _underlyingAssembly.FullName;

public string ImageRuntimeVersion => _underlyingAssembly.ImageRuntimeVersion;

public IModuleSymbol ManifestModule => ResolveModuleSymbol(_underlyingAssembly.ManifestModule);

public IEnumerable<IModuleSymbol> Modules => ResolveModuleSymbols(_underlyingAssembly.Modules);
Expand Down Expand Up @@ -79,44 +79,34 @@ public AssemblyName GetName()
return _underlyingAssembly.GetName();
}

public AssemblyName GetName(bool copiedName)
public ImmutableArray<AssemblyName> GetReferencedAssemblies()
{
return _underlyingAssembly.GetName(copiedName);
return _underlyingAssembly.GetReferencedAssemblies().ToImmutableArray();
}

public AssemblyName[] GetReferencedAssemblies()
public ITypeSymbol? GetType(string name)
{
return _underlyingAssembly.GetReferencedAssemblies();
return _underlyingAssembly.GetType(name) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
}

public ITypeSymbol? GetType(string name, bool throwOnError)
{
return _underlyingAssembly.GetType(name, throwOnError) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
}

public ITypeSymbol? GetType(string name, bool throwOnError, bool ignoreCase)
{
return _underlyingAssembly.GetType(name, throwOnError, ignoreCase) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
}

public ITypeSymbol? GetType(string name)
{
return _underlyingAssembly.GetType(name) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
}

public ITypeSymbol[] GetTypes()
{
return ResolveTypeSymbols(_underlyingAssembly.GetTypes());
}

public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes()
{
return ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData());
return _customAttributes.IsDefault ? _customAttributes = ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData()) : _customAttributes;
}

public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes(ITypeSymbol attributeType)
{
return ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData()).Where(i => i.AttributeType == attributeType).ToImmutableArray();
return GetCustomAttributes().Where(i => i.AttributeType == attributeType).ToImmutableArray();
}

public bool IsDefined(ITypeSymbol attributeType)
Expand Down

0 comments on commit 1249672

Please sign in to comment.