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 2014/09/02 01:48:48 UTC
svn commit: r1621901 - in
/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name:
Dn.java FastDnParser.java Rdn.java
Author: elecharny
Date: Mon Sep 1 23:48:47 2014
New Revision: 1621901
URL: http://svn.apache.org/r1621901
Log:
Speedup the Rdn parsing by using a char[] instead of a String
Modified:
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java?rev=1621901&r1=1621900&r2=1621901&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Dn.java Mon Sep 1 23:48:47 2014
@@ -1178,7 +1178,6 @@ public class Dn implements Iterable<Rdn>
{
if ( ( this.schemaManager == null ) || force )
{
-
this.schemaManager = schemaManager;
if ( this.schemaManager != null )
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java?rev=1621901&r1=1621900&r2=1621901&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/FastDnParser.java Mon Sep 1 23:48:47 2014
@@ -81,8 +81,10 @@ import org.apache.directory.api.util.Str
}
Position pos = new Position();
+ char[] chars = name.toCharArray();
+
pos.start = 0;
- pos.length = name.length();
+ pos.length = chars.length;
while ( true )
{
@@ -95,7 +97,9 @@ import org.apache.directory.api.util.Str
// end of line reached
break;
}
- char c = nextChar( name, pos, true );
+
+ char c = nextChar( chars, pos, true );
+
switch ( c )
{
case ',':
@@ -125,6 +129,7 @@ import org.apache.directory.api.util.Str
{
throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err( I18n.ERR_04193 ) );
}
+
if ( rdn == null )
{
throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err( I18n.ERR_04194 ) );
@@ -141,30 +146,31 @@ import org.apache.directory.api.util.Str
private static void parseRdnInternal( String name, Position pos, Rdn rdn ) throws LdapInvalidDnException
{
int rdnStart = pos.start;
+ char[] chars = name.toCharArray();
// SPACE*
- matchSpaces( name, pos );
+ matchSpaces( chars, pos );
// attributeType: ALPHA (ALPHA|DIGIT|HYPEN) | NUMERICOID
- String type = matchAttributeType( name, pos );
+ String type = matchAttributeType( chars, pos );
// SPACE*
- matchSpaces( name, pos );
+ matchSpaces( chars, pos );
// EQUALS
- matchEquals( name, pos );
+ matchEquals( chars, pos );
// SPACE*
- matchSpaces( name, pos );
+ matchSpaces( chars, pos );
// here we only match "simple" values
// stops at \ + # " -> Too Complex Exception
- String upValue = matchValue( name, pos );
+ String upValue = matchValue( chars, pos );
String value = Strings.trimRight( upValue );
// TODO: trim, normalize, etc
// SPACE*
- matchSpaces( name, pos );
+ matchSpaces( chars, pos );
String upName = name.substring( rdnStart, pos.start );
@@ -184,11 +190,12 @@ import org.apache.directory.api.util.Str
* @param pos the pos
* @throws LdapInvalidDnException
*/
- private static void matchSpaces( String name, Position pos ) throws LdapInvalidDnException
+ private static void matchSpaces( char[] name, Position pos ) throws LdapInvalidDnException
{
while ( hasMoreChars( pos ) )
{
char c = nextChar( name, pos, true );
+
if ( c != ' ' )
{
pos.start--;
@@ -208,9 +215,10 @@ import org.apache.directory.api.util.Str
*
* @throws LdapInvalidDnException the invalid name exception
*/
- private static String matchAttributeType( String name, Position pos ) throws LdapInvalidDnException
+ private static String matchAttributeType( char[] name, Position pos ) throws LdapInvalidDnException
{
char c = nextChar( name, pos, false );
+
switch ( c )
{
case 'A':
@@ -299,12 +307,14 @@ import org.apache.directory.api.util.Str
*
* @throws LdapInvalidDnException the invalid name exception
*/
- private static String matchAttributeTypeDescr( String name, Position pos ) throws LdapInvalidDnException
+ private static String matchAttributeTypeDescr( char[] name, Position pos ) throws LdapInvalidDnException
{
- StringBuilder descr = new StringBuilder();
+ int start = pos.start;
+
while ( hasMoreChars( pos ) )
{
char c = nextChar( name, pos, true );
+
switch ( c )
{
case 'A':
@@ -371,13 +381,12 @@ import org.apache.directory.api.util.Str
case '9':
case '-':
case '_': // Violation of the RFC, just because those idiots at Microsoft decided to support it...
- descr.append( c );
break;
case ' ':
case '=':
pos.start--;
- return descr.toString();
+ return new String( name, start, pos.start - start );
case '.':
// occurs for RDNs of form "oid.1.2.3=test"
@@ -389,7 +398,8 @@ import org.apache.directory.api.util.Str
pos.start ) );
}
}
- return descr.toString();
+
+ return new String( name, start, pos.start - start );
}
@@ -403,33 +413,37 @@ import org.apache.directory.api.util.Str
*
* @throws org.apache.directory.api.ldap.model.exception.LdapInvalidDnException the invalid name exception
*/
- private static String matchAttributeTypeNumericOid( String name, Position pos ) throws LdapInvalidDnException
+ private static String matchAttributeTypeNumericOid( char[] name, Position pos ) throws LdapInvalidDnException
{
- StringBuilder numericOid = new StringBuilder();
int dotCount = 0;
+ int start = pos.start;
+
while ( true )
{
char c = nextChar( name, pos, true );
+
switch ( c )
{
case '0':
// leading '0', no other digit may follow!
- numericOid.append( c );
c = nextChar( name, pos, true );
+
switch ( c )
{
case '.':
- numericOid.append( c );
dotCount++;
break;
+
case ' ':
case '=':
pos.start--;
break;
+
default:
throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err(
I18n.ERR_04197, c, pos.start ) );
}
+
break;
case '1':
@@ -441,11 +455,12 @@ import org.apache.directory.api.util.Str
case '7':
case '8':
case '9':
- numericOid.append( c );
boolean inInnerLoop = true;
+
while ( inInnerLoop )
{
c = nextChar( name, pos, true );
+
switch ( c )
{
case ' ':
@@ -453,6 +468,7 @@ import org.apache.directory.api.util.Str
inInnerLoop = false;
pos.start--;
break;
+
case '.':
inInnerLoop = false;
dotCount++;
@@ -467,25 +483,29 @@ import org.apache.directory.api.util.Str
case '7':
case '8':
case '9':
- numericOid.append( c );
break;
+
default:
throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err(
I18n.ERR_04197, c, pos.start ) );
}
}
+
break;
+
case ' ':
case '=':
pos.start--;
+
if ( dotCount > 0 )
{
- return numericOid.toString();
+ return new String( name, start, pos.start - start );
}
else
{
throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err( I18n.ERR_04198 ) );
}
+
default:
throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err( I18n.ERR_04199, c,
pos.start ) );
@@ -502,9 +522,10 @@ import org.apache.directory.api.util.Str
*
* @throws LdapInvalidDnException the invalid name exception
*/
- private static void matchEquals( String name, Position pos ) throws LdapInvalidDnException
+ private static void matchEquals( char[] name, Position pos ) throws LdapInvalidDnException
{
char c = nextChar( name, pos, true );
+
if ( c != '=' )
{
throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err( I18n.ERR_04200, c, pos.start ) );
@@ -524,9 +545,10 @@ import org.apache.directory.api.util.Str
*
* @throws LdapInvalidDnException the invalid name exception
*/
- private static String matchValue( String name, Position pos ) throws LdapInvalidDnException
+ private static String matchValue( char[] name, Position pos ) throws LdapInvalidDnException
{
- StringBuilder value = new StringBuilder();
+ //StringBuilder value = new StringBuilder();
+ int start = pos.start;
int numTrailingSpaces = 0;
while ( true )
@@ -534,7 +556,7 @@ import org.apache.directory.api.util.Str
if ( !hasMoreChars( pos ) )
{
pos.start -= numTrailingSpaces;
- return value.substring( 0, value.length() - numTrailingSpaces );
+ return new String( name, start, pos.start - start );
}
char c = nextChar( name, pos, true );
@@ -551,15 +573,14 @@ import org.apache.directory.api.util.Str
case ';':
pos.start--;
pos.start -= numTrailingSpaces;
- return value.substring( 0, value.length() - numTrailingSpaces );
+ return new String( name, start, pos.start - start );
case ' ':
numTrailingSpaces++;
- value.append( c );
break;
+
default:
numTrailingSpaces = 0;
- value.append( c );
}
}
}
@@ -575,17 +596,20 @@ import org.apache.directory.api.util.Str
* @return the character
* @throws LdapInvalidDnException If no more characters are available
*/
- private static char nextChar( String name, Position pos, boolean increment ) throws LdapInvalidDnException
+ private static char nextChar( char[] name, Position pos, boolean increment ) throws LdapInvalidDnException
{
if ( !hasMoreChars( pos ) )
{
throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, I18n.err( I18n.ERR_04201, pos.start ) );
}
- char c = name.charAt( pos.start );
+
+ char c = name[ pos.start ];
+
if ( increment )
{
pos.start++;
}
+
return c;
}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java?rev=1621901&r1=1621900&r2=1621901&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java Mon Sep 1 23:48:47 2014
@@ -1458,9 +1458,11 @@ public class Rdn implements Cloneable, E
public static boolean isValid( String dn )
{
Rdn rdn = new Rdn();
+
try
{
parse( dn, rdn );
+
return true;
}
catch ( LdapInvalidDnException e )