← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19668: minor speed improvements in node serializers

 

------------------------------------------------------------
revno: 19668
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-07-16 13:54:49 +0700
message:
  minor speed improvements in node serializers
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java	2015-03-11 08:04:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNode.java	2015-07-16 06:54:49 +0000
@@ -60,6 +60,8 @@
 
     protected List<Node> children = Lists.newArrayList();
 
+    protected ImmutableList<Node> sortedChildren;
+
     protected Property property;
 
     protected AbstractNode( String name, NodeType nodeType )
@@ -188,6 +190,8 @@
         children.add( child );
         ((AbstractNode) child).setParent( this );
 
+        sortedChildren = null;
+
         return child;
     }
 
@@ -198,6 +202,8 @@
         {
             children.remove( child );
         }
+
+        sortedChildren = null;
     }
 
     @Override
@@ -212,9 +218,14 @@
     @Override
     public List<Node> getChildren()
     {
-        List<Node> clone = Lists.newArrayList( children );
-        Collections.sort( clone, OrderComparator.INSTANCE );
-        return ImmutableList.copyOf( clone );
+        if ( sortedChildren == null )
+        {
+            List<Node> clone = Lists.newArrayList( children );
+            Collections.sort( clone, OrderComparator.INSTANCE );
+            sortedChildren = ImmutableList.copyOf( clone );
+        }
+
+        return sortedChildren;
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java	2015-07-16 06:27:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java	2015-07-16 06:54:49 +0000
@@ -115,10 +115,10 @@
         for ( Node node : complexNode.getChildren() )
         {
             dispatcher( node );
-            flushStream();
         }
 
         endWriteComplexNode( complexNode );
+        flushStream();
     }
 
     protected abstract void endWriteComplexNode( ComplexNode complexNode ) throws Exception;
@@ -137,10 +137,10 @@
         for ( Node node : collectionNode.getChildren() )
         {
             dispatcher( node );
-            flushStream();
         }
 
         endWriteCollectionNode( collectionNode );
+        flushStream();
     }
 
     protected abstract void endWriteCollectionNode( CollectionNode collectionNode ) throws Exception;