[prev in list] [next in list] [prev in thread] [next in thread] 

List:       slide-dev
Subject:    cvs commit: jakarta-slide/src/share/org/apache/slide/structure ObjectNode.java
From:       juergen () apache ! org
Date:       2003-02-25 16:43:37
[Download RAW message or body]

juergen     2003/02/25 08:43:37

  Modified:    src/share/org/apache/slide/structure ObjectNode.java
  Log:
  Performance: share the links and childs between object nodes. Thanks to Sven \
Steiniger [Sven.Steiniger@newtron.net]  
  Revision  Changes    Path
  1.8       +49 -12    \
jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java  
  Index: ObjectNode.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ObjectNode.java	25 Apr 2002 21:30:16 -0000	1.7
  +++ ObjectNode.java	25 Feb 2003 16:43:37 -0000	1.8
  @@ -120,16 +120,30 @@
       
       
       /**
  -     * Vector of children's Uris.
  +     * Vector of children's Uris. Before modifying this vector you must check
  +     * wheter {@link #childrenShared} is true. In this case clone the vector
  +     * and set the shared state to false.
        */
  -    protected Vector children = new Vector();
  -    
  -    
  +    private Vector children = new Vector();
  +
       /**
  -     * Vector of inbound links' Uris.
  +     * If true then the {@link #children} vector is shared between multiple
  +     * ObjectNode-instances and thus must not be modified.
        */
  -    protected Vector links = new Vector();
  +    private boolean childrenShared;
       
  +    /**
  +     * Vector of inbound links' Uris. Before modifying this vector you must check
  +     * wheter {@link #linksShared} is true. In this case clone the vector
  +     * and set the shared state to false.
  +     */
  +    private Vector links = new Vector();
  +
  +    /**
  +     * If true then the {@link #links} vector is shared between multiple
  +     * ObjectNode-instances and thus must not be modified.
  +     */
  +    private boolean linksShared;
       
       // ------------------------------------------------------------- Properties
       
  @@ -193,6 +207,12 @@
       void addChild(String uri) {
           if ((uri != null) && (!hasChild(uri))) {
               // We put a dummy object in the hashtable
  +            if(childrenShared)
  +            {
  +              // Lazy cloning on first write access
  +              children=(Vector)children.clone();
  +              childrenShared=false;
  +            }
               children.addElement(uri);
           }
       }
  @@ -202,7 +222,12 @@
        * Remove all children.
        */
       void removeChildren() {
  -        children.removeAllElements();
  +        if(childrenShared)
  +        {
  +          children=new Vector();
  +          childrenShared=false;
  +        }
  +        else children.removeAllElements();
       }
       
       
  @@ -212,6 +237,12 @@
        * @param uri Child's Uri
        */
       void removeChild(String uri) {
  +        if(childrenShared)
  +        {
  +          // Lazy cloning on first write access
  +          children=(Vector)children.clone();
  +          childrenShared=false;
  +        }
           children.removeElement(uri);
       }
       
  @@ -294,9 +325,13 @@
           ObjectNode result = null;
           
           try {
  +            // init the shared fields to let clone() copy them
  +            this.childrenShared=true;
  +            this.linksShared=true;
               result = (ObjectNode) super.clone();
  +            /* Old code removed because of lazy cloning
               result.children = (Vector) this.children.clone();
  -            result.links = (Vector) this.links.clone();
  +            result.links = (Vector) this.links.clone();*/
           } catch(CloneNotSupportedException e) {
               e.printStackTrace();
           }
  @@ -315,6 +350,8 @@
           
           try {
               result = (ObjectNode) super.clone();
  +            result.childrenShared=false;
  +            result.linksShared=false;
               result.children = new Vector();
               result.links = new Vector();
           } catch(CloneNotSupportedException e) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic