From e40b791b897dc91ce4227e7976054677515bbc3e Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Fri, 24 Apr 2009 20:34:14 +0000
Subject: [PATCH] Fix issue 3939: Wasteful memory allocation while sending search result entries.

---
 opends/src/server/org/opends/server/protocols/ldap/LDAPMessage.java |   40 +++++++++++-----------------------------
 1 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/opends/src/server/org/opends/server/protocols/ldap/LDAPMessage.java b/opends/src/server/org/opends/server/protocols/ldap/LDAPMessage.java
index 13f8a87..d2cab16 100644
--- a/opends/src/server/org/opends/server/protocols/ldap/LDAPMessage.java
+++ b/opends/src/server/org/opends/server/protocols/ldap/LDAPMessage.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2009 Sun Microsystems, Inc.
  */
 package org.opends.server.protocols.ldap;
 
@@ -56,7 +56,7 @@
   private final int messageID;
 
   // The protocol op for this LDAP message.
-  private ProtocolOp protocolOp;
+  private final ProtocolOp protocolOp;
 
 
 
@@ -69,10 +69,7 @@
    */
   public LDAPMessage(int messageID, ProtocolOp protocolOp)
   {
-    this.messageID  = messageID;
-    this.protocolOp = protocolOp;
-
-    controls = new ArrayList<Control>(0);
+    this(messageID, protocolOp, null);
   }
 
 
@@ -90,15 +87,7 @@
   {
     this.messageID  = messageID;
     this.protocolOp = protocolOp;
-
-    if (controls == null)
-    {
-      this.controls = new ArrayList<Control>(0);
-    }
-    else
-    {
-      this.controls = controls;
-    }
+    this.controls = controls;
   }
 
 
@@ -512,18 +501,6 @@
 
 
   /**
-   * Specifies the protocol op for this LDAP message.
-   *
-   * @param  protocolOp  The protocol op for this LDAP message.
-   */
-  public void setProtocolOp(ProtocolOp protocolOp)
-  {
-    this.protocolOp = protocolOp;
-  }
-
-
-
-  /**
    * Retrieves the set of controls for this LDAP message.  It may be modified by
    * the caller.
    *
@@ -531,6 +508,11 @@
    */
   public List<Control> getControls()
   {
+    // This method is not thread-safe.
+    if (controls == null)
+    {
+      controls = new ArrayList<Control>(0);
+    }
     return controls;
   }
 
@@ -546,7 +528,7 @@
     stream.writeInteger(messageID);
     protocolOp.write(stream);
 
-    if(!controls.isEmpty())
+    if(controls != null && !controls.isEmpty())
     {
       stream.writeStartSequence(TYPE_CONTROL_SEQUENCE);
       for(Control control : controls)
@@ -658,7 +640,7 @@
     buffer.append(EOL);
     protocolOp.toString(buffer, indent+4);
 
-    if (! controls.isEmpty())
+    if (controls != null && !controls.isEmpty())
     {
       buffer.append(indentBuf);
       buffer.append("  Controls:");

--
Gitblit v1.10.0