You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2023/02/14 03:13:56 UTC

[directory-ldap-api] branch master updated: Some more optimization of the Rdn parser

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

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git


The following commit(s) were added to refs/heads/master by this push:
     new 11cb032b4 Some more optimization of the Rdn parser
11cb032b4 is described below

commit 11cb032b4c21bb4b1cf83c68aca149b107e681ec
Author: emmanuel lecharny <el...@apache.org>
AuthorDate: Tue Feb 14 04:13:53 2023 +0100

    Some more optimization of the Rdn parser
---
 .../api/ldap/model/name/FastDnParser.java          | 57 ++++++++++------------
 1 file changed, 26 insertions(+), 31 deletions(-)

diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
index db601b09a..f89e64635 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
@@ -156,19 +156,11 @@ import org.apache.directory.api.util.Strings;
             throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err( I18n.ERR_13602_RDN_EMPTY ) );
         }
 
-        if ( rdn == null )
-        {
-            throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err( I18n.ERR_13603_NULL_RDN ) );
-        }
-
         Position pos = new Position();
         pos.start = 0;
         pos.length = name.length();
-        StringBuilder sb = new StringBuilder();
 
         parseRdnInternal( schemaManager, name, pos, rdn );
-        
-        sb.append( rdn.getNormName() );
     }
 
 
@@ -200,20 +192,29 @@ import org.apache.directory.api.util.Strings;
         // SPACE*
         matchSpaces( chars, pos );
 
-        String upName = name.substring( rdnStart, pos.start );
-        
-        Ava ava = new Ava( schemaManager, type, upValue );
-        rdn.addAVA( schemaManager, ava );
-
-        if ( schemaManager != null )
+        if ( rdn != null )
         {
-            AttributeType attributeType = ava.getAttributeType();
+            String upName = name.substring( rdnStart, pos.start );
+            Ava ava = new Ava( schemaManager, type, upValue );
             
-            if ( attributeType != null )
+            rdn.addAVA( schemaManager, ava );
+        
+            if ( schemaManager != null )
             {
-                sbNormName.append( ava.getNormType() );
-                sbNormName.append( '=' );
-                sbNormName.append( ava.getValue().getNormalized() );
+                AttributeType attributeType = ava.getAttributeType();
+                
+                if ( attributeType != null )
+                {
+                    sbNormName.append( ava.getNormType() );
+                    sbNormName.append( '=' );
+                    sbNormName.append( ava.getValue().getNormalized() );
+                }
+                else
+                {
+                    sbNormName.append( type );
+                    sbNormName.append( '=' );
+                    sbNormName.append( upValue );
+                }
             }
             else
             {
@@ -221,17 +222,11 @@ import org.apache.directory.api.util.Strings;
                 sbNormName.append( '=' );
                 sbNormName.append( upValue );
             }
-        }
-        else
-        {
-            sbNormName.append( type );
-            sbNormName.append( '=' );
-            sbNormName.append( upValue );
-        }
 
-        rdn.setUpName( upName );
-        rdn.setNormName( sbNormName.toString() );
-        rdn.hashCode();
+            rdn.setUpName( upName );
+            rdn.setNormName( sbNormName.toString() );
+            rdn.hashCode();
+        }
     }
 
 
@@ -625,8 +620,8 @@ import org.apache.directory.api.util.Strings;
                 case ',':
                 case ';':
                     pos.start--;
-                    pos.start -= numTrailingSpaces;
-                    return new String( name, start, pos.start - start );
+                    //pos.start -= numTrailingSpaces;
+                    return new String( name, start, pos.start - numTrailingSpaces - start );
 
                 case ' ':
                     numTrailingSpaces++;