[jboss-cvs] JBossCache/src/org/jboss/cache ...

Manik Surtani manik at jboss.org
Tue Jun 19 09:09:14 EDT 2007


  User: msurtani
  Date: 07/06/19 09:09:14

  Modified:    src/org/jboss/cache  Fqn.java
  Log:
  Cached toString reps of Fqns
  
  Revision  Changes    Path
  1.54      +18 -6     JBossCache/src/org/jboss/cache/Fqn.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Fqn.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Fqn.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -b -r1.53 -r1.54
  --- Fqn.java	11 Jun 2007 15:06:02 -0000	1.53
  +++ Fqn.java	19 Jun 2007 13:09:14 -0000	1.54
  @@ -58,7 +58,7 @@
    * Another way to look at it is that the "/" separarator is only parsed when it forms
    * part of a String passed in to Fqn.fromString() and not otherwise.
    *
  - * @version $Revision: 1.53 $
  + * @version $Revision: 1.54 $
    */
   @Immutable
   public class Fqn<E> implements Cloneable, Externalizable, Comparable<Fqn>
  @@ -77,6 +77,8 @@
       */
      public static final Fqn ROOT = new Fqn();
      private static Log log = LogFactory.getLog(Fqn.class);
  +   // a cached string representation of this Fqn, used by toString to it isn't calculated again every time.
  +   private String cachedStringRep;
   
      /**
       * Constructs a root Fqn
  @@ -331,13 +333,23 @@
       */
      public String toString()
      {
  -      if (isRoot()) return SEPARATOR;
  +      if (cachedStringRep == null)
  +      {
  +         if (isRoot())
  +         {
  +            cachedStringRep = SEPARATOR;
  +         }
  +         else
  +         {
         StringBuffer sb = new StringBuffer();
         for (E element : elements)
         {
            sb.append(SEPARATOR).append(element);
         }
  -      return sb.toString();
  +            cachedStringRep = sb.toString();
  +         }
  +      }
  +      return cachedStringRep;
      }
   
      public void writeExternal(ObjectOutput out) throws IOException
  
  
  



More information about the jboss-cvs-commits mailing list