[tasks] avoid passing dupe assemblies to Cecil (#4624) fixes #4620
authorStephane Delcroix <stephane@delcroix.org>
Tue, 4 Dec 2018 18:17:54 +0000 (19:17 +0100)
committerRui Marinho <me@ruimarinho.net>
Tue, 4 Dec 2018 18:17:54 +0000 (18:17 +0000)
* [tasks] avoid passing dupe assemblies to Cecil

avoid feeding Mono.Cecil with dupes. Removes a negligeable handful
of milliseconds (100ms on average, hard to measure) from XamlC. Even
less from XamlG.

- fixes #4620

* add extra check

Xamarin.Forms.Build.Tasks/XamlCTask.cs
Xamarin.Forms.Build.Tasks/XamlGenerator.cs

index 3390de4..01d8e8e 100644 (file)
@@ -48,14 +48,14 @@ namespace Xamarin.Forms.Build.Tasks
                        var resolver = DefaultAssemblyResolver ?? new XamlCAssemblyResolver();
                        if (resolver is XamlCAssemblyResolver xamlCResolver) {
                                if (!string.IsNullOrEmpty(DependencyPaths)) {
-                                       foreach (var dep in DependencyPaths.Split(';')) {
+                                       foreach (var dep in DependencyPaths.Split(';').Distinct()) {
                                                LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Adding searchpath {dep}");
                                                xamlCResolver.AddSearchDirectory(dep);
                                        }
                                }
 
                                if (!string.IsNullOrEmpty(ReferencePath)) {
-                                       var paths = ReferencePath.Replace("//", "/").Split(';');
+                                       var paths = ReferencePath.Replace("//", "/").Split(';').Distinct();
                                        foreach (var p in paths) {
                                                var searchpath = Path.GetDirectoryName(p);
                                                LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Adding searchpath {searchpath}");
index 453f3b7..073bd7e 100644 (file)
@@ -385,20 +385,20 @@ namespace Xamarin.Forms.Build.Tasks
                        _xmlnsDefinitions = new List<XmlnsDefinitionAttribute>();
                        _xmlnsModules = new Dictionary<string, ModuleDefinition>();
 
-                       if (string.IsNullOrEmpty(this.References))
+                       if (string.IsNullOrEmpty(References))
                                return;
 
-                       string[] paths = this.References.Split(';');
+                       string[] paths = References.Split(';').Distinct().ToArray();
 
-                       foreach ( var path in paths ) {
+                       foreach (var path in paths) {
                                string asmName = Path.GetFileName(path);
-                               if ( AssemblyIsSystem(asmName) )
+                               if (AssemblyIsSystem(asmName))
                                        // Skip the myriad "System." assemblies and others
                                        continue;                               
 
                                using (var asmDef = AssemblyDefinition.ReadAssembly(path)) {
-                                       foreach ( var ca in asmDef.CustomAttributes ) {
-                                               if ( ca.AttributeType.FullName == typeof(XmlnsDefinitionAttribute).FullName) {
+                                       foreach (var ca in asmDef.CustomAttributes) {
+                                               if (ca.AttributeType.FullName == typeof(XmlnsDefinitionAttribute).FullName) {
                                                        _xmlnsDefinitions.Add(ca.GetXmlnsDefinition(asmDef));
                                                        _xmlnsModules[asmDef.FullName] = asmDef.MainModule;
                                                }