felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1668536 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: capabilityset/CapabilitySet.java util/StringComparator.java util/StringMap.java
Date Mon, 23 Mar 2015 08:18:22 GMT
Author: gnodet
Date: Mon Mar 23 08:18:22 2015
New Revision: 1668536

URL: http://svn.apache.org/r1668536
Log:
[FELIX-4821] Reuse the fast case insensitive comparator for the CapabilitySet indices

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/StringComparator.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/StringMap.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java?rev=1668536&r1=1668535&r2=1668536&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/capabilityset/CapabilitySet.java
Mon Mar 23 08:18:22 2015
@@ -81,7 +81,7 @@ public class CapabilitySet
         m_indices = (caseSensitive)
             ? new TreeMap<String, Map<Object, Set<BundleCapability>>>()
             : new TreeMap<String, Map<Object, Set<BundleCapability>>>(
-                new StringComparator(false));
+                StringComparator.COMPARATOR);
         for (int i = 0; (indexProps != null) && (i < indexProps.size()); i++)
         {
             m_indices.put(

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/StringComparator.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/StringComparator.java?rev=1668536&r1=1668535&r2=1668536&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/StringComparator.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/StringComparator.java
Mon Mar 23 08:18:22 2015
@@ -20,29 +20,54 @@ package org.apache.felix.framework.util;
 
 import java.util.Comparator;
 
-public class StringComparator implements Comparator
+public class StringComparator implements Comparator<String>
 {
-    private final boolean m_isCaseSensitive;
 
-    public StringComparator(boolean b)
-    {
-        m_isCaseSensitive = b;
-    }
+    public static final StringComparator COMPARATOR = new StringComparator();
 
-    public int compare(Object o1, Object o2)
+    public int compare(String s1, String s2)
     {
-        if (m_isCaseSensitive)
-        {
-            return o1.toString().compareTo(o2.toString());
-        }
-        else
+        int n1 = s1.length();
+        int n2 = s2.length();
+        int min = n1 < n2 ? n1 : n2;
+        for ( int i = 0; i < min; i++ )
         {
-            return o1.toString().compareToIgnoreCase(o2.toString());
+            char c1 = s1.charAt( i );
+            char c2 = s2.charAt( i );
+            if ( c1 != c2 )
+            {
+                // Fast check for simple ascii codes
+                if ( c1 <= 128 && c2 <= 128 )
+                {
+                    c1 = toLowerCaseFast(c1);
+                    c2 = toLowerCaseFast(c2);
+                    if ( c1 != c2 )
+                    {
+                        return c1 - c2;
+                    }
+                }
+                else
+                {
+                    c1 = Character.toUpperCase( c1 );
+                    c2 = Character.toUpperCase( c2 );
+                    if ( c1 != c2 )
+                    {
+                        c1 = Character.toLowerCase( c1 );
+                        c2 = Character.toLowerCase( c2 );
+                        if ( c1 != c2 )
+                        {
+                            // No overflow because of numeric promotion
+                            return c1 - c2;
+                        }
+                    }
+                }
+            }
         }
+        return n1 - n2;
     }
 
-    public boolean isCaseSensitive()
+    private static char toLowerCaseFast( char ch )
     {
-        return m_isCaseSensitive;
+        return ( ch >= 'A' && ch <= 'Z' ) ? ( char ) ( ch + 'a' - 'A' ) : ch;
     }
 }
\ No newline at end of file

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/StringMap.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/StringMap.java?rev=1668536&r1=1668535&r2=1668536&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/StringMap.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/StringMap.java Mon
Mar 23 08:18:22 2015
@@ -18,7 +18,6 @@
  */
 package org.apache.felix.framework.util;
 
-import java.util.Comparator;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -32,70 +31,19 @@ import java.util.TreeMap;
  **/
 public class StringMap extends TreeMap<String, Object>
 {
-    private static final CaseInsensitiveComparator COMPARATOR = new CaseInsensitiveComparator();
 
     public StringMap()
     {
-        super(COMPARATOR);
+        super(StringComparator.COMPARATOR);
     }
 
     public StringMap(Map<?, ?> map)
     {
-        super(COMPARATOR);
+        this();
         for (Map.Entry<?, ?> e : map.entrySet())
         {
             put(e.getKey().toString(), e.getValue());
         }
     }
 
-    private static class CaseInsensitiveComparator implements Comparator<String>
-    {
-
-        public int compare(String s1, String s2)
-        {
-            int n1 = s1.length();
-            int n2 = s2.length();
-            int min = n1 < n2 ? n1 : n2;
-            for ( int i = 0; i < min; i++ )
-            {
-                char c1 = s1.charAt( i );
-                char c2 = s2.charAt( i );
-                if ( c1 != c2 )
-                {
-                    // Fast check for simple ascii codes
-                    if ( c1 <= 128 && c2 <= 128 )
-                    {
-                        c1 = toLowerCaseFast(c1);
-                        c2 = toLowerCaseFast(c2);
-                        if ( c1 != c2 )
-                        {
-                            return c1 - c2;
-                        }
-                    }
-                    else
-                    {
-                        c1 = Character.toUpperCase( c1 );
-                        c2 = Character.toUpperCase( c2 );
-                        if ( c1 != c2 )
-                        {
-                            c1 = Character.toLowerCase( c1 );
-                            c2 = Character.toLowerCase( c2 );
-                            if ( c1 != c2 )
-                            {
-                                // No overflow because of numeric promotion
-                                return c1 - c2;
-                            }
-                        }
-                    }
-                }
-            }
-            return n1 - n2;
-        }
-    }
-
-    private static char toLowerCaseFast( char ch )
-    {
-        return ( ch >= 'A' && ch <= 'Z' ) ? ( char ) ( ch + 'a' - 'A' ) : ch;
-    }
-
 }



Mime
View raw message