From 313f49f82bba13b9108d095f54b3cad571962673 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 29 Oct 2014 10:14:04 +0000
Subject: [PATCH] DN.java: In toIrreversibleNormalizedByteString(), avoid uselessly creating a StringBuilder.

---
 opendj-core/src/main/java/org/forgerock/opendj/ldap/DN.java |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/DN.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/DN.java
index 1cd8d2d..629256b 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/DN.java
+++ b/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--) {

--
Gitblit v1.10.0