directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r201861 - /directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java
Date Sun, 26 Jun 2005 14:52:39 GMT
Author: elecharny
Date: Sun Jun 26 07:52:38 2005
New Revision: 201861

URL: http://svn.apache.org/viewcvs?rev=201861&view=rev
Log:
Improved the inferLdapName method by avoiding re-creation of strings during the parsing 
(no more 'realm = realm.substring( dotIndex + 1 );')

25% faster.

Modified:
    directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java

Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java?rev=201861&r1=201860&r2=201861&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java
(original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/util/NamespaceTools.java
Sun Jun 26 07:52:38 2005
@@ -448,29 +448,27 @@
      */
     public static String inferLdapName( String realm )
     {
-        StringBuffer buf = new StringBuffer();
-
-        while ( realm != null && ! realm.equals( "" ) )
+        if (StringTools.isEmpty(realm))
         {
-            int dotIndex = realm.indexOf( '.' );
+            return "";
+        }
+        
+        StringBuffer buf = new StringBuffer(realm.length());
+        buf.append("dc=");
+        
+        int start = 0, end = 0;
 
-            if ( dotIndex != -1 )
-            {
-                String component = realm.substring( 0, dotIndex );
-                buf.append( "dc=" );
-                buf.append( component );
-                buf.append( ',' );
+        // Replace all the '.' by ",dc=". The comma is added because
+        // the string is not supposed to start with a dot, so another
+        // dc=XXXX already exists in any cases.
+        // The realm is also not supposed to finish with a '.'
+        while ((end = realm.indexOf('.', start)) != -1) {
+            buf.append(realm.substring(start, end)).append(",dc=");
+            start = end + 1;
 
-                realm = realm.substring( dotIndex + 1 );
-            }
-            else if ( realm.length() > 0 )
-            {
-                buf.append( "dc=" );
-                buf.append( realm );
-                realm = null;
-            }
         }
 
+        buf.append(realm.substring(start));
         return buf.toString();
     }
 }



Mime
View raw message