maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [maven] gnodet commented on a change in pull request #262: Improve speed in collection merging
Date Mon, 01 Jul 2019 18:46:04 GMT
gnodet commented on a change in pull request #262: Improve speed in collection merging
URL: https://github.com/apache/maven/pull/262#discussion_r299171614
 
 

 ##########
 File path: maven-model/src/main/java/org/apache/maven/model/merge/ModelMerger.java
 ##########
 @@ -3018,4 +2618,298 @@ protected Object getExclusionKey( Exclusion exclusion )
         return exclusion;
     }
 
+    interface KeyComputer<T>
+    {
+        Object key( T t );
+    }
+
+    class DependencyKeyComputer implements KeyComputer<Dependency>
+    {
+        @Override
+        public Object key( Dependency dependency )
+        {
+            return getDependencyKey( dependency );
+        }
+    }
+
+    class LicenseKeyComputer implements KeyComputer<License>
+    {
+        @Override
+        public Object key( License license )
+        {
+            return getLicenseKey( license );
+        }
+    }
+
+    class MailingListKeyComputer implements KeyComputer<MailingList>
+    {
+        @Override
+        public Object key( MailingList mailingList )
+        {
+            return getMailingListKey( mailingList );
+        }
+    }
+
+    class DeveloperKeyComputer implements KeyComputer<Developer>
+    {
+        @Override
+        public Object key( Developer developer )
+        {
+            return getDeveloperKey( developer );
+        }
+    }
+
+    class ContributorKeyComputer implements KeyComputer<Contributor>
+    {
+        @Override
+        public Object key( Contributor contributor )
+        {
+            return getContributorKey( contributor );
+        }
+    }
+
+    class ProfileKeyComputer implements KeyComputer<Profile>
+    {
+        @Override
+        public Object key( Profile profile )
+        {
+            return getProfileKey( profile );
+        }
+    }
+
+    class RepositoryKeyComputer implements KeyComputer<Repository>
+    {
+        @Override
+        public Object key( Repository repository )
+        {
+            return getRepositoryKey( repository );
+        }
+    }
+
+    class ReportPluginKeyComputer implements KeyComputer<ReportPlugin>
+    {
+        @Override
+        public Object key( ReportPlugin plugin )
+        {
+            return getReportPluginKey( plugin );
+        }
+    }
+
+    class PluginKeyComputer implements KeyComputer<Plugin>
+    {
+        @Override
+        public Object key( Plugin plugin )
+        {
+            return getPluginKey( plugin );
+        }
+    }
+
+    class ReportSetKeyComputer implements KeyComputer<ReportSet>
+    {
+        @Override
+        public Object key( ReportSet reportSet )
+        {
+            return getReportSetKey( reportSet );
+        }
+    }
+
+    class NotifierKeyComputer implements KeyComputer<Notifier>
+    {
+        @Override
+        public Object key( Notifier notifier )
+        {
+            return getNotifierKey( notifier );
+        }
+    }
+
+    class ExtensionKeyComputer implements KeyComputer<Extension>
+    {
+        @Override
+        public Object key( Extension extension )
+        {
+            return getExtensionKey( extension );
+        }
+    }
+
+    class ResourceKeyComputer implements KeyComputer<Resource>
+    {
+        @Override
+        public Object key( Resource resource )
+        {
+            return getResourceKey( resource );
+        }
+    }
+
+    class ExecutionKeyComputer implements KeyComputer<PluginExecution>
+    {
+        @Override
+        public Object key( PluginExecution pluginExecution )
+        {
+            return getPluginExecutionKey( pluginExecution );
+        }
+    }
+
+    class ExclusionKeyComputer implements KeyComputer<Exclusion>
+    {
+        @Override
+        public Object key( Exclusion exclusion )
+        {
+            return getExclusionKey( exclusion );
+        }
+    }
+
+    static <T> List<T> merge( List<T> tgt, List<T> src, boolean sourceDominant,
KeyComputer<T> computer )
+    {
+        if ( src.isEmpty() )
+        {
+            return tgt;
+        }
+
+        MergingList<T> list;
+        if ( tgt instanceof MergingList )
+        {
+            list = (MergingList<T>) tgt;
+        }
+        else
+        {
+            list = new MergingList<>( computer, src.size() + tgt.size() );
+            list.mergeAll( tgt, true );
+        }
+
+        list.mergeAll( src, sourceDominant );
+        return list;
+    }
+
+    /**
+     * Merging list
+     * @param <V>
+     */
+    public static class MergingList<V> extends AbstractList<V>
 
 Review comment:
   @Tibor17 My goal here is just speed performances, nothing else. I don't want to refactor
anything and my main goal is to keep 100% compatibility.  That's the reasons for the sometime
weird choices that were made in this PR.
   I don't think the `List` interface specific methods such as `listIterator`, `add(Object,
int)` or such are used at all, but given the aim of 100% compatibility, I decided to make
them available in the resulting collection.  So while your suggestions may be totally appropriate,
this would not be compatible, so this is definitely a separate discussion, a separate jira
issue, and a separate target release (i'm aiming for 100% compatibility to have this included
in a 3.6.2 if possible).
   
   The `c instanceof MergingList` has been added to be able to reuse this dual data structure
and avoid switching between the map and list quite a few times.  I'll add a commit to make
the `MergingList` private and the `KeyComputer` protected (so that they can be reused in the
later derived classes).  Again the KeyComputer interface and implementations should completely
go away once Maven requires JDK8, but again, that's a different target/discussion.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message