Skip to content

Commit 04d3fc9

Browse files
authored
[Xamarin.Android.Build.Tasks] Fix up ToJniName to use cache. (#7460)
Context: dotnet/java-interop@b81cfbb The `ManifestDocument` class has a few instances of `ToJniName` that are not using the `cache` overload. Using the `cache` version should be faster, so lets try to use that :) This required plumbing the `cache` variable through another few methods as well.
1 parent 9159aca commit 04d3fc9

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public IList<string> Merge (TaskLoggingHelper log, TypeDefinitionCache cache, Li
336336
if (PackageName == null)
337337
PackageName = t.Namespace;
338338

339-
var name = JavaNativeTypeManager.ToJniName (t).Replace ('/', '.');
339+
var name = JavaNativeTypeManager.ToJniName (t, cache).Replace ('/', '.');
340340
var compatName = JavaNativeTypeManager.ToCompatJniName (t, cache).Replace ('/', '.');
341341
if (((string) app.Attribute (attName)) == compatName) {
342342
app.SetAttributeValue (attName, name);
@@ -927,7 +927,7 @@ void AddInstrumentations (XElement manifest, IList<TypeDefinition> subclasses, i
927927

928928
foreach (var type in subclasses)
929929
if (type.IsSubclassOf ("Android.App.Instrumentation", cache)) {
930-
var xe = InstrumentationFromTypeDefinition (type, JavaNativeTypeManager.ToJniName (type).Replace ('/', '.'), targetSdkVersion);
930+
var xe = InstrumentationFromTypeDefinition (type, JavaNativeTypeManager.ToJniName (type, cache).Replace ('/', '.'), targetSdkVersion);
931931
if (xe != null)
932932
manifest.Add (xe);
933933
}

src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public bool Generate (bool debugBuild, bool skipJniAddNativeMethodRegistrationAt
142142
return GenerateDebug (skipJniAddNativeMethodRegistrationAttributeScan, javaTypes, cache, typemapsOutputDirectory, generateNativeAssembly, appConfState);
143143
}
144144

145-
return GenerateRelease (skipJniAddNativeMethodRegistrationAttributeScan, javaTypes, typemapsOutputDirectory, appConfState);
145+
return GenerateRelease (skipJniAddNativeMethodRegistrationAttributeScan, javaTypes, cache, typemapsOutputDirectory, appConfState);
146146
}
147147

148148
bool GenerateDebug (bool skipJniAddNativeMethodRegistrationAttributeScan, List<TypeDefinition> javaTypes, TypeDefinitionCache cache, string outputDirectory, bool generateNativeAssembly, ApplicationConfigTaskState appConfState)
@@ -186,7 +186,7 @@ bool GenerateDebugFiles (bool skipJniAddNativeMethodRegistrationAttributeScan, L
186186
modules.Add (moduleName, module);
187187
}
188188

189-
TypeMapDebugEntry entry = GetDebugEntry (td);
189+
TypeMapDebugEntry entry = GetDebugEntry (td, cache);
190190
HandleDebugDuplicates (javaDuplicates, entry, td, cache);
191191
if (entry.JavaName.Length > module.JavaNameWidth)
192192
module.JavaNameWidth = (uint)entry.JavaName.Length + 1;
@@ -227,7 +227,7 @@ bool GenerateDebugNativeAssembly (bool skipJniAddNativeMethodRegistrationAttribu
227227
foreach (TypeDefinition td in javaTypes) {
228228
UpdateApplicationConfig (td, appConfState);
229229

230-
TypeMapDebugEntry entry = GetDebugEntry (td);
230+
TypeMapDebugEntry entry = GetDebugEntry (td, cache);
231231
HandleDebugDuplicates (javaDuplicates, entry, td, cache);
232232

233233
javaToManaged.Add (entry);
@@ -300,10 +300,10 @@ void PrepareDebugMaps (ModuleDebugData module)
300300
}
301301
}
302302

303-
TypeMapDebugEntry GetDebugEntry (TypeDefinition td)
303+
TypeMapDebugEntry GetDebugEntry (TypeDefinition td, TypeDefinitionCache cache)
304304
{
305305
return new TypeMapDebugEntry {
306-
JavaName = Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniName (td),
306+
JavaName = Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniName (td, cache),
307307
ManagedName = GetManagedTypeName (td),
308308
TypeDefinition = td,
309309
SkipInJavaToManaged = ShouldSkipInJavaToManaged (td),
@@ -330,7 +330,7 @@ string GetManagedTypeName (TypeDefinition td)
330330
return $"{managedTypeName}, {td.Module.Assembly.Name.Name}";
331331
}
332332

333-
bool GenerateRelease (bool skipJniAddNativeMethodRegistrationAttributeScan, List<TypeDefinition> javaTypes, string outputDirectory, ApplicationConfigTaskState appConfState)
333+
bool GenerateRelease (bool skipJniAddNativeMethodRegistrationAttributeScan, List<TypeDefinition> javaTypes, TypeDefinitionCache cache, string outputDirectory, ApplicationConfigTaskState appConfState)
334334
{
335335
int assemblyId = 0;
336336
var knownAssemblies = new Dictionary<string, int> (StringComparer.Ordinal);
@@ -373,7 +373,7 @@ bool GenerateRelease (bool skipJniAddNativeMethodRegistrationAttributeScan, List
373373
tempModules.Add (moduleUUID, moduleData);
374374
}
375375

376-
string javaName = Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniName (td);
376+
string javaName = Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniName (td, cache);
377377
// We will ignore generic types and interfaces when generating the Java to Managed map, but we must not
378378
// omit them from the table we output - we need the same number of entries in both java-to-managed and
379379
// managed-to-java tables. `SkipInJavaToManaged` set to `true` will cause the native assembly generator

0 commit comments

Comments
 (0)