mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
29.14.2014 313f49f82bba13b9108d095f54b3cad571962673
DN.java:
In toIrreversibleNormalizedByteString(), avoid uselessly creating a StringBuilder.
1 files modified
21 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/DN.java 21 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/DN.java
@@ -22,14 +22,10 @@
 *
 *
 *      Copyright 2009-2010 Sun Microsystems, Inc.
 *      Portions copyright 2011-2012 ForgeRock AS.
 *      Portions copyright 2011-2014 ForgeRock AS.
 */
package org.forgerock.opendj.ldap;
import static com.forgerock.opendj.util.StaticUtils.getBytes;
import static com.forgerock.opendj.ldap.CoreMessages.ERR_DN_TYPE_NOT_FOUND;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -49,6 +45,9 @@
import com.forgerock.opendj.util.StaticUtils;
import com.forgerock.opendj.util.SubstringReader;
import static com.forgerock.opendj.ldap.CoreMessages.*;
import static com.forgerock.opendj.util.StaticUtils.*;
/**
 * A distinguished name (DN) as defined in RFC 4512 section 2.3 is the
 * concatenation of its relative distinguished name (RDN) and its immediate
@@ -274,10 +273,9 @@
            if (dn2.isRootDN()) {
                // both are equal.
                return 0;
            } else {
                // dn1 comes before dn2.
                return -1;
            }
            // dn1 comes before dn2.
            return -1;
        }
        if (dn2.isRootDN()) {
@@ -483,6 +481,7 @@
    }
    /** {@inheritDoc} */
    @Override
    public int compareTo(final DN dn) {
        return compareTo(this, dn);
    }
@@ -740,14 +739,17 @@
     *
     * @return An iterator of the RDNs contained in this DN.
     */
    @Override
    public Iterator<RDN> iterator() {
        return new Iterator<RDN>() {
            private DN dn = DN.this;
            @Override
            public boolean hasNext() {
                return dn.rdn != null;
            }
            @Override
            public RDN next() {
                if (dn.rdn == null) {
                    throw new NoSuchElementException();
@@ -758,6 +760,7 @@
                return rdn;
            }
            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }
@@ -921,11 +924,11 @@
     * @return The normalized string representation of the provided DN, not usable as a valid DN
     */
    public ByteString toIrreversibleNormalizedByteString() {
        final StringBuilder builder = new StringBuilder(size());
        if (rdn() == null) {
            return ByteString.empty();
        }
        final StringBuilder builder = new StringBuilder(size());
        int i = size() - 1;
        normalizeRDN(builder, parent(i).rdn());
        for (i--; i >= 0; i--) {