Skip to content

Commit 1249672

Browse files
committed
Remove a few unused things.
Cache attributes.
1 parent efb056f commit 1249672

File tree

3 files changed

+33
-75
lines changed

3 files changed

+33
-75
lines changed

src/IKVM.CoreLib/Symbols/IAssemblySymbol.cs

+5-26
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ interface IAssemblySymbol : ISymbol, ICustomAttributeSymbolProvider
3131
/// </summary>
3232
string? FullName { get; }
3333

34-
/// <summary>
35-
/// Gets a string representing the version of the common language runtime (CLR) saved in the file containing the manifest.
36-
/// </summary>
37-
string ImageRuntimeVersion { get; }
38-
3934
/// <summary>
4035
/// Gets the module that contains the manifest for the current assembly.
4136
/// </summary>
@@ -78,42 +73,26 @@ interface IAssemblySymbol : ISymbol, ICustomAttributeSymbolProvider
7873
/// <returns></returns>
7974
AssemblyName GetName();
8075

81-
/// <summary>
82-
/// Gets an <see cref="AssemblyName"/> for this assembly, setting the codebase as specified by <paramref name="copiedName"/>.
83-
/// </summary>
84-
/// <param name="copiedName"></param>
85-
/// <returns></returns>
86-
AssemblyName GetName(bool copiedName);
87-
8876
/// <summary>
8977
/// Gets the <see cref="AssemblyName"/> objects for all the assemblies referenced by this assembly.
9078
/// </summary>
9179
/// <returns></returns>
92-
AssemblyName[] GetReferencedAssemblies();
80+
ImmutableArray<AssemblyName> GetReferencedAssemblies();
9381

9482
/// <summary>
95-
/// 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.
83+
/// Gets the <see cref="ITypeSymbol"/> object with the specified name in the assembly instance.
9684
/// </summary>
9785
/// <param name="name"></param>
98-
/// <param name="throwOnError"></param>
9986
/// <returns></returns>
100-
ITypeSymbol? GetType(string name, bool throwOnError);
87+
ITypeSymbol? GetType(string name);
10188

10289
/// <summary>
103-
/// 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.
90+
/// 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.
10491
/// </summary>
10592
/// <param name="name"></param>
10693
/// <param name="throwOnError"></param>
107-
/// <param name="ignoreCase"></param>
108-
/// <returns></returns>
109-
ITypeSymbol? GetType(string name, bool throwOnError, bool ignoreCase);
110-
111-
/// <summary>
112-
/// Gets the <see cref="Type"/> object with the specified name in the assembly instance.
113-
/// </summary>
114-
/// <param name="name"></param>
11594
/// <returns></returns>
116-
ITypeSymbol? GetType(string name);
95+
ITypeSymbol? GetType(string name, bool throwOnError);
11796

11897
/// <summary>
11998
/// Gets all types defined in this assembly.

src/IKVM.CoreLib/Symbols/IkvmReflection/IkvmReflectionAssemblySymbol.cs

+17-28
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class IkvmReflectionAssemblySymbol : IkvmReflectionSymbol, IAssemblySymbol
1919
readonly ConditionalWeakTable<Module, IkvmReflectionModuleSymbol> _modules = new();
2020

2121
System.Reflection.AssemblyName? _assemblyName;
22+
ImmutableArray<CustomAttributeSymbol> _customAttributes = default;
2223

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

4647
internal Assembly UnderlyingAssembly => _underlyingAssembly;
4748

48-
public IEnumerable<ITypeSymbol> DefinedTypes => ResolveTypeSymbols(_underlyingAssembly.DefinedTypes);
49-
50-
public IMethodSymbol? EntryPoint => _underlyingAssembly.EntryPoint is { } m ? ResolveMethodSymbol(m) : null;
51-
52-
public IEnumerable<ITypeSymbol> ExportedTypes => ResolveTypeSymbols(_underlyingAssembly.ExportedTypes);
53-
5449
public string? FullName => _underlyingAssembly.FullName;
5550

56-
public string ImageRuntimeVersion => _underlyingAssembly.ImageRuntimeVersion;
57-
5851
public IModuleSymbol ManifestModule => ResolveModuleSymbol(_underlyingAssembly.ManifestModule);
5952

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

55+
public IEnumerable<ITypeSymbol> DefinedTypes => ResolveTypeSymbols(_underlyingAssembly.DefinedTypes);
56+
57+
public IEnumerable<ITypeSymbol> ExportedTypes => ResolveTypeSymbols(_underlyingAssembly.ExportedTypes);
58+
59+
public IMethodSymbol? EntryPoint => _underlyingAssembly.EntryPoint is { } m ? ResolveMethodSymbol(m) : null;
60+
6261
public override bool IsMissing => _underlyingAssembly.__IsMissing;
6362

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

104-
public System.Reflection.AssemblyName GetName(bool copiedName)
103+
public ImmutableArray<System.Reflection.AssemblyName> GetReferencedAssemblies()
105104
{
106-
return ToName(_underlyingAssembly.GetName());
107-
}
108-
109-
public System.Reflection.AssemblyName[] GetReferencedAssemblies()
110-
{
111-
var l = _underlyingAssembly.GetReferencedAssemblies();
112-
var a = new System.Reflection.AssemblyName[l.Length];
105+
var l = _underlyingAssembly.GetReferencedAssemblies().ToImmutableArray();
106+
var a = ImmutableArray.CreateBuilder<System.Reflection.AssemblyName>(l.Length);
113107
for (int i = 0; i < l.Length; i++)
114-
a[i] = ToName(l[i]);
115-
116-
return a;
117-
}
108+
a.Add(ToName(l[i]));
118109

119-
public ITypeSymbol? GetType(string name, bool throwOnError)
120-
{
121-
return _underlyingAssembly.GetType(name, throwOnError) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
110+
return a.DrainToImmutable();
122111
}
123112

124-
public ITypeSymbol? GetType(string name, bool throwOnError, bool ignoreCase)
113+
public ITypeSymbol? GetType(string name)
125114
{
126-
return _underlyingAssembly.GetType(name, throwOnError, ignoreCase) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
115+
return _underlyingAssembly.GetType(name) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
127116
}
128117

129-
public ITypeSymbol? GetType(string name)
118+
public ITypeSymbol? GetType(string name, bool throwOnError)
130119
{
131-
return _underlyingAssembly.GetType(name) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
120+
return _underlyingAssembly.GetType(name, throwOnError) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
132121
}
133122

134123
public ITypeSymbol[] GetTypes()
@@ -138,7 +127,7 @@ public ITypeSymbol[] GetTypes()
138127

139128
public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes()
140129
{
141-
return ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData());
130+
return _customAttributes.IsDefault ? _customAttributes = ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData()) : _customAttributes;
142131
}
143132

144133
public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes(ITypeSymbol attributeType)

src/IKVM.CoreLib/Symbols/Reflection/ReflectionAssemblySymbol.cs

+11-21
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ class ReflectionAssemblySymbol : ReflectionSymbol, IAssemblySymbol
1515
readonly Assembly _underlyingAssembly;
1616
readonly ConditionalWeakTable<Module, ReflectionModuleSymbol> _modules = new();
1717

18+
ImmutableArray<CustomAttributeSymbol> _customAttributes = default;
19+
1820
/// <summary>
1921
/// Initializes a new instance.
2022
/// </summary>
2123
/// <param name="context"></param>
22-
/// <param name="assembly"></param>
23-
public ReflectionAssemblySymbol(ReflectionSymbolContext context, Assembly assembly) :
24+
/// <param name="underlyingAssembly"></param>
25+
public ReflectionAssemblySymbol(ReflectionSymbolContext context, Assembly underlyingAssembly) :
2426
base(context)
2527
{
26-
_underlyingAssembly = assembly ?? throw new ArgumentNullException(nameof(assembly));
28+
_underlyingAssembly = underlyingAssembly ?? throw new ArgumentNullException(nameof(underlyingAssembly));
2729
}
2830

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

4951
public string? FullName => _underlyingAssembly.FullName;
5052

51-
public string ImageRuntimeVersion => _underlyingAssembly.ImageRuntimeVersion;
52-
5353
public IModuleSymbol ManifestModule => ResolveModuleSymbol(_underlyingAssembly.ManifestModule);
5454

5555
public IEnumerable<IModuleSymbol> Modules => ResolveModuleSymbols(_underlyingAssembly.Modules);
@@ -79,44 +79,34 @@ public AssemblyName GetName()
7979
return _underlyingAssembly.GetName();
8080
}
8181

82-
public AssemblyName GetName(bool copiedName)
82+
public ImmutableArray<AssemblyName> GetReferencedAssemblies()
8383
{
84-
return _underlyingAssembly.GetName(copiedName);
84+
return _underlyingAssembly.GetReferencedAssemblies().ToImmutableArray();
8585
}
8686

87-
public AssemblyName[] GetReferencedAssemblies()
87+
public ITypeSymbol? GetType(string name)
8888
{
89-
return _underlyingAssembly.GetReferencedAssemblies();
89+
return _underlyingAssembly.GetType(name) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
9090
}
9191

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

97-
public ITypeSymbol? GetType(string name, bool throwOnError, bool ignoreCase)
98-
{
99-
return _underlyingAssembly.GetType(name, throwOnError, ignoreCase) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
100-
}
101-
102-
public ITypeSymbol? GetType(string name)
103-
{
104-
return _underlyingAssembly.GetType(name) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
105-
}
106-
10797
public ITypeSymbol[] GetTypes()
10898
{
10999
return ResolveTypeSymbols(_underlyingAssembly.GetTypes());
110100
}
111101

112102
public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes()
113103
{
114-
return ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData());
104+
return _customAttributes.IsDefault ? _customAttributes = ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData()) : _customAttributes;
115105
}
116106

117107
public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes(ITypeSymbol attributeType)
118108
{
119-
return ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData()).Where(i => i.AttributeType == attributeType).ToImmutableArray();
109+
return GetCustomAttributes().Where(i => i.AttributeType == attributeType).ToImmutableArray();
120110
}
121111

122112
public bool IsDefined(ITypeSymbol attributeType)

0 commit comments

Comments
 (0)