Hello,

I have recently been trying to give the monodoc assembler a bit of a
performance boost. The following patch gives us a 12% increase by 1)
reducing the number of xpath queries and 2) not writing temp files. It
also reduces memory consumption.

May I commit?

-- Ben
Index: ecma-provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/ecma-provider.cs,v
retrieving revision 1.49
diff -u -r1.49 ecma-provider.cs
--- ecma-provider.cs	15 Jun 2003 18:53:27 -0000	1.49
+++ ecma-provider.cs	19 Jun 2003 02:58:38 -0000
@@ -31,34 +31,34 @@
 // Helper routines to extract information from an Ecma XML document
 //
 public class EcmaDoc {
-	public static string GetFullClassName (XmlDocument doc)
+	public static string GetFullClassName (XmlNode typeNode)
 	{
-		return doc.SelectSingleNode ("/Type").Attributes ["FullName"].InnerText;
+		return typeNode.Attributes ["FullName"].InnerText;
 	}
 	
-	public static string GetClassName (XmlDocument doc)
+	public static string GetClassName (XmlNode typeNode)
 	{
-		return doc.SelectSingleNode ("/Type").Attributes ["Name"].InnerText;
+		return typeNode.Attributes ["Name"].InnerText;
 	}
 
-	public static string GetClassAssembly (XmlDocument doc)
+	public static string GetClassAssembly (XmlNode typeNode)
 	{
-		return doc.SelectSingleNode ("/Type/AssemblyInfo/AssemblyName").InnerText;
+		return typeNode.SelectSingleNode ("AssemblyInfo/AssemblyName").InnerText;
 	}
 
-	public static string GetClassNamespace (XmlDocument doc)
+	public static string GetClassNamespace (XmlNode typeNode)
 	{
-		string s = doc.SelectSingleNode ("/Type").Attributes ["FullName"].InnerText;
+		string s = GetFullClassName (typeNode);
 
 		return s.Substring (0, s.LastIndexOf ("."));
 	}
 	
-	public static string GetTypeKind (XmlDocument doc)
+	public static string GetTypeKind (XmlNode typeNode)
 	{
-		XmlNode node = doc.SelectSingleNode ("/Type/Base/BaseTypeName");
+		XmlNode node = typeNode.SelectSingleNode ("Base/BaseTypeName");
 
 		if (node == null){
-			if (GetFullClassName (doc) == "System.Object")
+			if (GetFullClassName (typeNode) == "System.Object")
 				return "Class";
 			return "Interface";
 		}
@@ -191,71 +191,70 @@
 	public override void CloseTree (HelpSource hs, Tree tree)
 	{
 		foreach (DictionaryEntry de in class_summaries){
-			XmlDocument doc = new XmlDocument ();
 			string ns = (string) de.Key;
-			
 			ArrayList list = (ArrayList) de.Value;
-			list.Sort();
-
-			XmlElement elements = doc.CreateElement ("elements");
-			doc.AppendChild (elements);
+			list.Sort ();
 			
-			string file = "xml.summary." + ns;
 			Console.Error.WriteLine ("Have {0} elements in the {1}", list.Count, ns);
+			
+			XmlTextWriter w = hs.PackXmlWriter ("xml.summary." + ns);
+			
+			w.WriteStartElement ("elements");
+
 			foreach (TypeInfo p in list){
-				XmlElement e = null;
-				
 				switch (p.type_kind){
 				case "Class":
-					e = doc.CreateElement ("class"); 
+					w.WriteStartElement ("class"); 
 					break;
 					
 				case "Enumeration":
-					e = doc.CreateElement ("enum");
+					w.WriteStartElement ("enum");
 					break;
 					
 				case "Structure":
-					e = doc.CreateElement ("struct");
+					w.WriteStartElement ("struct");
 					break;
 					
 				case "Delegate":
-					e = doc.CreateElement ("delegate");
+					w.WriteStartElement ("delegate");
 					break;
 					
 				case "Interface":
-					e = doc.CreateElement ("interface");
+					w.WriteStartElement ("interface");
 					break;
 				}
-				
-				e.SetAttribute ("name", p.type_name);
-				e.SetAttribute ("fullname", p.type_full);
-				e.SetAttribute ("assembly", p.type_assembly);
-				XmlNode copy = doc.ImportNode (p.type_doc, true);
-				e.AppendChild (copy);
-				elements.AppendChild (e);
+				w.WriteAttributeString ("name", p.type_name);
+				w.WriteAttributeString ("fullname", p.type_full);
+				w.WriteAttributeString ("assembly", p.type_assembly);
+
+				p.type_doc.WriteTo (w);
+				w.WriteEndElement ();
 			}
-			hs.PackXml ("xml.summary." + ns, doc);
+			
+			w.WriteEndDocument();
 		}
 	}
 	       
 	static Hashtable class_summaries = new Hashtable ();
 					     
-	XmlDocument doc;
+	XmlNode typeNode;
 	
 	void PopulateClass (string ns, Node ns_node, string file)
 	{
-		doc = new XmlDocument ();
+		XmlDocument doc = new XmlDocument ();
 		doc.Load (file);
 		
-		string name = EcmaDoc.GetClassName (doc);
-		string assembly = EcmaDoc.GetClassAssembly (doc);
-		string kind = EcmaDoc.GetTypeKind (doc);
-		string full = EcmaDoc.GetFullClassName (doc);
+		typeNode = doc.SelectSingleNode ("/Type");
+		
+		string name = EcmaDoc.GetClassName (typeNode);
+		string assembly = EcmaDoc.GetClassAssembly (typeNode);
+		string kind = EcmaDoc.GetTypeKind (typeNode);
+		string full = EcmaDoc.GetFullClassName (typeNode);
 
 		Node class_node;
 		string file_code = ns_node.tree.HelpSource.PackFile (file);
 
-		XmlNode class_summary = doc.SelectSingleNode ("/Type/Docs/summary");
+		XmlNode class_summary = typeNode.SelectSingleNode ("Docs/summary");
 		ArrayList l = (ArrayList) class_summaries [ns];
 		if (l == null)
 			l = class_summaries [ns] = new ArrayList ();
@@ -316,7 +315,7 @@
 	//
 	void PopulateMember (string typename, Node node, string text, string plural_text)
 	{
-		XmlNodeList list = doc.SelectNodes (String.Format ("/Type/Members/Member[MemberType=\"{0}\"]", text));
+		XmlNodeList list = typeNode.SelectNodes (String.Format ("Members/Member[MemberType=\"{0}\"]", text));
 		int count = list.Count;
 		
 		if (count == 0)
Index: provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/provider.cs,v
retrieving revision 1.28
diff -u -r1.28 provider.cs
--- provider.cs	1 Jun 2003 15:26:45 -0000	1.28
+++ provider.cs	19 Jun 2003 02:58:38 -0000
@@ -470,11 +470,12 @@
 
 		return entry_name;
 	}
-	
-	public void PackXml (string fname, XmlDocument doc)
+		
+	public System.Xml.XmlTextWriter PackXmlWriter (string entry_name)
 	{
-		doc.Save ("tmp");
-		PackFile ("tmp", fname);
+		ZipEntry entry = new ZipEntry (entry_name);
+		zip_output.PutNextEntry (entry);
+		return new System.Xml.XmlTextWriter (zip_output, null);
 	}
 	
 	public virtual string GetText (string url, out Node n)

Reply via email to