You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2019/01/23 10:01:46 UTC

[maven] branch MNG-6571 created (now a415a9e)

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a change to branch MNG-6571
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at a415a9e  [MNG-6571] cache VersionRange instances, they are immutable

This branch includes the following new commits:

     new a415a9e  [MNG-6571] cache VersionRange instances, they are immutable

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven] 01/01: [MNG-6571] cache VersionRange instances, they are immutable

Posted by hb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch MNG-6571
in repository https://gitbox.apache.org/repos/asf/maven.git

commit a415a9e808a9e052d863d161549e522a3492bd59
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Wed Jan 23 11:01:18 2019 +0100

    [MNG-6571] cache VersionRange instances, they are immutable
---
 .../org/apache/maven/artifact/versioning/VersionRange.java  | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java
index e919621..409b51d 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.WeakHashMap;
 
 import org.apache.maven.artifact.Artifact;
 
@@ -33,6 +34,8 @@ import org.apache.maven.artifact.Artifact;
  */
 public class VersionRange
 {
+    private static final WeakHashMap<String, VersionRange> CACHE = new WeakHashMap<>();
+
     private final ArtifactVersion recommendedVersion;
 
     private final List<Restriction> restrictions;
@@ -97,6 +100,12 @@ public class VersionRange
             return null;
         }
 
+        VersionRange cached = CACHE.get( spec );
+        if ( cached != null )
+        {
+            return cached;
+        }
+
         List<Restriction> restrictions = new ArrayList<>();
         String process = spec;
         ArtifactVersion version = null;
@@ -159,7 +168,9 @@ public class VersionRange
             }
         }
 
-        return new VersionRange( version, restrictions );
+        cached = new VersionRange( version, restrictions );
+        CACHE.put( spec, new VersionRange( version, restrictions ) );
+        return cached;
     }
 
     private static Restriction parseRestriction( String spec )