From a838b2185a2f14baa2893fdf94c2e6d3af363690 Mon Sep 17 00:00:00 2001 From: "etsai%netscape.com" Date: Wed, 3 Mar 2004 15:09:59 +0000 Subject: [PATCH] Performance enhancement for big group entry, 231623 --- .../netscape/jndi/ldap/AttributesImpl.java | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/directory/java-sdk/ldapsp/com/netscape/jndi/ldap/AttributesImpl.java b/directory/java-sdk/ldapsp/com/netscape/jndi/ldap/AttributesImpl.java index 4bcb46d30d9..52a2dc5e445 100644 --- a/directory/java-sdk/ldapsp/com/netscape/jndi/ldap/AttributesImpl.java +++ b/directory/java-sdk/ldapsp/com/netscape/jndi/ldap/AttributesImpl.java @@ -18,6 +18,7 @@ * Rights Reserved. * * Contributor(s): + * Luke (lukemz@onemodel.org) */ package com.netscape.jndi.ldap; @@ -189,12 +190,37 @@ class AttributesImpl implements Attributes { } else { enumVals = attr.getStringValues(); - } - if (enumVals != null) { - while ( enumVals.hasMoreElements() ) { - jndiAttr.add(enumVals.nextElement()); - } - } + } + /* Performance enhancement for an attribute with many values. + * If number of value over threshold, use TreeSet to quickly + * eliminate value duplication. Locally extends JNDI attribute + * to pass TreeSet directly to Vector of JNDI attribute. + */ + if (attr.size() < 50 ) { + if (enumVals != null) { + while ( enumVals.hasMoreElements() ) { + jndiAttr.add(enumVals.nextElement()); + } + } + } + else { + /* A local class to allow constructing a JNDI attribute + * from a TreeSet. + */ + class BigAttribute extends BasicAttribute { + public BigAttribute (String id, TreeSet val) { + super(id); + values = new Vector (val); + } + } + TreeSet valSet = new TreeSet(); + if (enumVals != null) { + while ( enumVals.hasMoreElements() ) { + valSet.add(enumVals.nextElement()); + } + } + jndiAttr = new BigAttribute(attr.getName(), valSet); + } return jndiAttr; }