[mapguide-commits] r5894 - in branches/2.2/MgDev/Web/src: mapviewerjava mapviewernet

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Jun 1 08:16:08 EDT 2011


Author: jng
Date: 2011-06-01 05:16:08 -0700 (Wed, 01 Jun 2011)
New Revision: 5894

Modified:
   branches/2.2/MgDev/Web/src/mapviewerjava/legend.jsp
   branches/2.2/MgDev/Web/src/mapviewernet/legend.aspx
Log:
#1451: Use StringBuilder and StringBuffer for legend.aspx and legend.jsp respectively as these perform significantly faster than raw string concatenation (due to immutability of strings). For large (100+ layer) map legends, this should have a notice performance improvement. PHP strings are mutable and does not require such optimization.

Modified: branches/2.2/MgDev/Web/src/mapviewerjava/legend.jsp
===================================================================
--- branches/2.2/MgDev/Web/src/mapviewerjava/legend.jsp	2011-06-01 11:16:13 UTC (rev 5893)
+++ branches/2.2/MgDev/Web/src/mapviewerjava/legend.jsp	2011-06-01 12:16:08 UTC (rev 5894)
@@ -65,7 +65,7 @@
 boolean summary = false;
 int layerCount = 0;
 int intermediateVar = 0;
-String output = "\nvar layerData = new Array();\n";
+StringBuffer output = new StringBuffer("\nvar layerData = new Array();\n");
 
 %>
 
@@ -76,9 +76,6 @@
 
 try
 {
-    output = "\nvar layerData = new Array();\n";
-    intermediateVar = 0;
-
     // Initialize web tier with the site configuration file.
     InitializeWebTier();
 
@@ -129,7 +126,7 @@
     //load html template code and format it
     //
     String templ = LoadTemplate("/viewerfiles/legendupdate.templ");
-    String vals[] = { String.valueOf(updateType), output, GetSurroundVirtualPath(request) + "legend.jsp"};
+    String vals[] = { String.valueOf(updateType), output.toString(), GetSurroundVirtualPath(request) + "legend.jsp"};
     String outputString = Substitute(templ, vals);
 
     writer.write(outputString);
@@ -282,7 +279,7 @@
                     if(node.children != null)
                     {
                         arrChildName = "c" + (intermediateVar++);
-                        output = output + "var " + arrChildName + " = new Array();\n";
+                        output.append("var " + arrChildName + " = new Array();\n");
                     }
                     else
                         arrChildName = "null";
@@ -290,7 +287,7 @@
                     MgLayerGroup rtLayerGroup = (MgLayerGroup)node.rtObject;
                     if(fulldata)
                     {
-                        output = output + String.format("var %s = new GroupItem(\"%s\", %s, %s, %s, %s, \"%s\", \"%s\", %s);\n",
+                        output.append(String.format("var %s = new GroupItem(\"%s\", %s, %s, %s, %s, \"%s\", \"%s\", %s);\n",
                                                            new Object[] {groupName,
                                                            StrEscape(rtLayerGroup.GetLegendLabel()),
                                                            rtLayerGroup.GetExpandInLegend()? "true": "false",
@@ -299,24 +296,24 @@
                                                            rtLayerGroup.GetDisplayInLegend()? "true": "false",
                                                            rtLayerGroup.GetObjectId(),
                                                            StrEscape(rtLayerGroup.GetName()),
-                                                           rtLayerGroup.GetLayerGroupType() == MgLayerGroupType.BaseMap? "true": "false"});
+                                                           rtLayerGroup.GetLayerGroupType() == MgLayerGroupType.BaseMap? "true": "false"}));
                     }
                     else
                     {
-                        output = output + String.format("var %s = new GroupSummary(\"%s\", \"%s\", %s, %s);\n",
+                        output.append(String.format("var %s = new GroupSummary(\"%s\", \"%s\", %s, %s);\n",
                                                            new Object[] {groupName,
                                                            StrEscape(rtLayerGroup.GetName()),
                                                            rtLayerGroup.GetObjectId(),
                                                            arrChildName,
-                                                           parentName});
+                                                           parentName}));
                     }
-                    output = output + String.format("%s[%d] = %s;\n", new Object[] {container, Integer.valueOf(treeIndex), groupName});
+                    output.append(String.format("%s[%d] = %s;\n", new Object[] {container, Integer.valueOf(treeIndex), groupName}));
                     ++treeIndex;
 
                     if(node.children != null)
                     {
                         BuildClientSideTree(node.children, node, groupName, fulldata, arrChildName, resSrvc, null);
-                        output = output + String.format("%s.children = %s;\n", new Object[] {groupName, arrChildName});
+                        output.append(String.format("%s.children = %s;\n", new Object[] {groupName, arrChildName}));
                     }
                 }
             }
@@ -331,7 +328,7 @@
                         String layerData = node.layerData;
                         String layerName = "lyr" + (intermediateVar++);
                         String objectId = rtLayer.GetObjectId();
-                        output = output + String.format("var %s = new LayerItem(\"%s\", \"%s\", %s, %s, %s, %s, %s, \"%s\", \"%s\", %s);\n",
+                        output.append(String.format("var %s = new LayerItem(\"%s\", \"%s\", %s, %s, %s, %s, %s, \"%s\", \"%s\", %s);\n",
                                                            new Object[] {layerName,
                                                            StrEscape(rtLayer.GetLegendLabel()),
                                                            rtLayer.GetName(),
@@ -342,12 +339,12 @@
                                                            rtLayer.GetSelectable()? "true": "false",
                                                            resId.ToString(),
                                                            objectId,
-                                                           rtLayer.GetLayerType() == MgLayerType.BaseMap? "true": "false"});
+                                                           rtLayer.GetLayerType() == MgLayerType.BaseMap? "true": "false"}));
 
-                        output = output + String.format("%s[%d] = %s;\n",
+                        output.append(String.format("%s[%d] = %s;\n",
                                                            new Object[] {container,
                                                            Integer.valueOf(treeIndex),
-                                                           layerName});
+                                                           layerName}));
                         ++treeIndex;
 
                         if(layerMap == null || !layerMap.containsKey(objectId))
@@ -357,12 +354,12 @@
                     }
                     else
                     {
-                        output = output + String.format("%s[%d] = new LayerSummary(\"%s\", \"%s\", \"%s\");\n",
+                        output.append(String.format("%s[%d] = new LayerSummary(\"%s\", \"%s\", \"%s\");\n",
                                                             new Object[] {container,
                                                             Integer.valueOf(i),
                                                             StrEscape(rtLayer.GetName()),
                                                             rtLayer.GetObjectId(),
-                                                            rtLayer.GetLayerDefinition().ToString()});
+                                                            rtLayer.GetLayerDefinition().ToString()}));
                     }
                 }
             }
@@ -410,12 +407,12 @@
                 minScale = minElt.item(0).getChildNodes().item(0).getNodeValue().toString();
             if(maxElt.getLength() > 0)
                 maxScale = maxElt.item(0).getChildNodes().item(0).getNodeValue().toString();
-            output = output + String.format("var %s = new ScaleRangeItem(%s, %s, %s);\n",
+            output.append(String.format("var %s = new ScaleRangeItem(%s, %s, %s);\n",
                                         new Object[]{scaleRangeVarName,
                                         minScale,
                                         maxScale,
-                                        layerVarName});
-            output = output + String.format("%s.children[%d] = %s;\n", new Object[] {layerVarName, Integer.valueOf(sc), scaleRangeVarName});
+                                        layerVarName}));
+            output.append(String.format("%s.children[%d] = %s;\n", new Object[] {layerVarName, Integer.valueOf(sc), scaleRangeVarName}));
 
             if(type != 0)
                 break;
@@ -455,18 +452,18 @@
                                 filterText = subItems2.item(0).getNodeValue();
                         }
 
-                        output = output + String.format("%s.children[%d] = new StyleItem(\"%s\", \"%s\", %d, %d);\n",
+                        output.append(String.format("%s.children[%d] = new StyleItem(\"%s\", \"%s\", %d, %d);\n",
                                                     new Object[]{scaleRangeVarName,
                                                     Integer.valueOf(styleIndex++),
                                                     StrEscape(labelText.trim()),
                                                     StrEscape(filterText.trim()),
                                                     ts+1,
-                                                    catIndex++});
+                                                    catIndex++}));
                     }
                 }
             }
         }
-        output = output + String.format("%s.lyrtype = %d;\n", new Object[]{layerVarName, new Integer(type) });
+        output.append(String.format("%s.lyrtype = %d;\n", new Object[]{layerVarName, new Integer(type) }));
     }
     catch(Exception e)
     {

Modified: branches/2.2/MgDev/Web/src/mapviewernet/legend.aspx
===================================================================
--- branches/2.2/MgDev/Web/src/mapviewernet/legend.aspx	2011-06-01 11:16:13 UTC (rev 5893)
+++ branches/2.2/MgDev/Web/src/mapviewernet/legend.aspx	2011-06-01 12:16:08 UTC (rev 5894)
@@ -20,6 +20,7 @@
 <%@ Import Namespace="System.Collections" %>
 <%@ Import Namespace="System.Collections.Specialized" %>
 <%@ Import Namespace="System.Web" %>
+<%@ Import Namespace="System.Text" %>
 <%@ Import Namespace="System.Globalization" %>
 <%@ Import Namespace="System.Xml" %>
 <%@ Import Namespace="OSGeo.MapGuide" %>
@@ -64,7 +65,7 @@
 bool summary = false;
 int layerCount = 0;
 int intermediateVar = 0;
-String output = "\nvar layerData = new Array();\n";
+StringBuilder output = new StringBuilder("\nvar layerData = new Array();\n");
 </script>
 
 <%
@@ -122,7 +123,7 @@
         //
         String templ = LoadTemplate(Request, "../viewerfiles/legendupdate.templ");
         String[] vals = { updateType.ToString(NumberFormatInfo.InvariantInfo),
-            output,
+            output.ToString(),
             GetSurroundVirtualPath(Request) + "legend.aspx"};
         String outputString = Substitute(templ, vals);
 
@@ -282,7 +283,7 @@
                     if(node.children != null)
                     {
                         arrChildName = "c" + (intermediateVar++);
-                        output = output + "var " + arrChildName + " = new Array();\n";
+                        output.Append("var " + arrChildName + " = new Array();\n");
                     }
                     else
                     {
@@ -292,7 +293,7 @@
                     MgLayerGroup rtLayerGroup = (MgLayerGroup)node.rtObject;
                     if(fulldata)
                     {
-                        output = output + String.Format("var {0} = new GroupItem(\"{1}\", {2}, {3}, {4},{5}, \"{6}\", \"{7}\", {8});\n",
+                        output.Append(String.Format("var {0} = new GroupItem(\"{1}\", {2}, {3}, {4},{5}, \"{6}\", \"{7}\", {8});\n",
                                                         groupName,
                                                         StrEscape(rtLayerGroup.GetLegendLabel()),
                                                         rtLayerGroup.GetExpandInLegend()? "true": "false",
@@ -301,24 +302,24 @@
                                                         rtLayerGroup.GetDisplayInLegend() ? "true" : "false",
                                                         rtLayerGroup.GetObjectId(),
                                                         StrEscape(rtLayerGroup.GetName()),
-                                                        rtLayerGroup.GetLayerGroupType() == MgLayerGroupType.BaseMap? "true": "false");
+                                                        rtLayerGroup.GetLayerGroupType() == MgLayerGroupType.BaseMap? "true": "false"));
                     }
                     else
                     {
-                        output = output + String.Format("var {0} = new GroupSummary(\"{1}\", \"{2}\", {3}, {4});\n",
+                        output.Append(String.Format("var {0} = new GroupSummary(\"{1}\", \"{2}\", {3}, {4});\n",
                                                         groupName,
                                                         StrEscape(rtLayerGroup.GetName()),
                                                         rtLayerGroup.GetObjectId(),
                                                         arrChildName,
-                                                        parentName);
+                                                        parentName));
                     }
-                    output = output + String.Format("{0}[{1}] = {2};\n", container, treeIndex, groupName);
+                    output.Append(String.Format("{0}[{1}] = {2};\n", container, treeIndex, groupName));
                     ++treeIndex;
 
                     if(node.children != null)
                     {
                         BuildClientSideTree(node.children, node, groupName, fulldata, arrChildName, resSrvc, null);
-                        output = output + String.Format("{0}.children = {1};\n", groupName, arrChildName);
+                        output.Append(String.Format("{0}.children = {1};\n", groupName, arrChildName));
                     }
                 }
             }
@@ -333,7 +334,7 @@
                         String layerData = node.layerData;
                         String layerName = "lyr" + (intermediateVar++);
                         String objectId = rtLayer.GetObjectId();
-                        output = output + String.Format("var {0} = new LayerItem(\"{1}\", \"{2}\", {3}, {4}, {5}, {6}, {7}, \"{8}\", \"{9}\", {10});\n",
+                        output.Append(String.Format("var {0} = new LayerItem(\"{1}\", \"{2}\", {3}, {4}, {5}, {6}, {7}, \"{8}\", \"{9}\", {10});\n",
                                                         layerName,
                                                         rtLayer.GetLegendLabel(),
                                                         StrEscape(rtLayer.GetName()),
@@ -344,12 +345,12 @@
                                                         rtLayer.GetSelectable() ? "true" : "false",
                                                         resId.ToString(),
                                                         objectId,
-                                                        rtLayer.GetLayerType() == MgLayerType.BaseMap? "true": "false");
+                                                        rtLayer.GetLayerType() == MgLayerType.BaseMap? "true": "false"));
 
-                        output = output + String.Format("{0}[{1}] = {2};\n",
+                        output.Append(String.Format("{0}[{1}] = {2};\n",
                                                         container,
                                                         treeIndex,
-                                                        layerName);
+                                                        layerName));
                         ++treeIndex;
 
                         if(layerMap == null || !layerMap.ContainsKey(objectId))
@@ -359,12 +360,12 @@
                     }
                     else
                     {
-                        output = output + String.Format("{0}[{1}] = new LayerSummary(\"{2}\", \"{3}\", \"{4}\");\n",
+                        output.Append(String.Format("{0}[{1}] = new LayerSummary(\"{2}\", \"{3}\", \"{4}\");\n",
                                                             container,
                                                             i,
                                                             rtLayer.GetName(),
                                                             rtLayer.GetObjectId(),
-                                                            rtLayer.GetLayerDefinition().ToString());
+                                                            rtLayer.GetLayerDefinition().ToString()));
                     }
                 }
             }
@@ -410,12 +411,12 @@
             if(maxElt.Count > 0)
                 maxScale = maxElt[0].ChildNodes[0].Value;
             String scaleRangeVarName = "sc" + (intermediateVar++);
-            output = output + String.Format("var {0} = new ScaleRangeItem({1}, {2}, {3});\n",
+            output.Append(String.Format("var {0} = new ScaleRangeItem({1}, {2}, {3});\n",
                                         scaleRangeVarName,
                                         minScale,
                                         maxScale,
-                                        layerVarName);
-            output = output + String.Format("{0}.children[{1}] = {2};\n", layerVarName, sc, scaleRangeVarName);
+                                        layerVarName));
+            output.Append(String.Format("{0}.children[{1}] = {2};\n", layerVarName, sc, scaleRangeVarName));
 
             if(type != 0)
                 break;
@@ -447,18 +448,18 @@
                         if(filter != null && filter.Count > 0 && filter[0].ChildNodes.Count > 0)
                             filterText = filter[0].ChildNodes[0].Value;
 
-                        output = output + String.Format("{0}.children[{1}] = new StyleItem(\"{2}\", \"{3}\", {4}, {5});\n",
+                        output.Append(String.Format("{0}.children[{1}] = new StyleItem(\"{2}\", \"{3}\", {4}, {5});\n",
                                                     scaleRangeVarName,
                                                     styleIndex++,
                                                     StrEscape(labelText.Trim()),
                                                     StrEscape(filterText.Trim()),
                                                     ts+1,
-                                                    catIndex++);
+                                                    catIndex++));
                     }
                 }
             }
         }
-        output = output + String.Format("{0}.lyrtype = {1};\n", layerVarName, type.ToString(NumberFormatInfo.InvariantInfo) );
+        output.Append(String.Format("{0}.lyrtype = {1};\n", layerVarName, type.ToString(NumberFormatInfo.InvariantInfo) ));
     }
     catch(Exception e)
     {



More information about the mapguide-commits mailing list