[Mono-docs-list] Monodoc patch
Ben Maurer
bmaurer@users.sourceforge.net
18 Jun 2003 22:50:36 -0400
--=-enAtDK22+JYv7Jn4N0GI
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
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
--=-enAtDK22+JYv7Jn4N0GI
Content-Disposition: attachment; filename=monodocperf.patch
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=monodocperf.patch; charset=UTF-8
Index: ecma-provider.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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;
}
=09
- public static string GetClassName (XmlDocument doc)
+ public static string GetClassName (XmlNode typeNode)
{
- return doc.SelectSingleNode ("/Type").Attributes ["Name"].InnerText;
+ return typeNode.Attributes ["Name"].InnerText;
}
=20
- public static string GetClassAssembly (XmlDocument doc)
+ public static string GetClassAssembly (XmlNode typeNode)
{
- return doc.SelectSingleNode ("/Type/AssemblyInfo/AssemblyName").InnerTex=
t;
+ return typeNode.SelectSingleNode ("AssemblyInfo/AssemblyName").InnerText=
;
}
=20
- public static string GetClassNamespace (XmlDocument doc)
+ public static string GetClassNamespace (XmlNode typeNode)
{
- string s =3D doc.SelectSingleNode ("/Type").Attributes ["FullName"].Inne=
rText;
+ string s =3D GetFullClassName (typeNode);
=20
return s.Substring (0, s.LastIndexOf ("."));
}
=09
- public static string GetTypeKind (XmlDocument doc)
+ public static string GetTypeKind (XmlNode typeNode)
{
- XmlNode node =3D doc.SelectSingleNode ("/Type/Base/BaseTypeName");
+ XmlNode node =3D typeNode.SelectSingleNode ("Base/BaseTypeName");
=20
if (node =3D=3D null){
- if (GetFullClassName (doc) =3D=3D "System.Object")
+ if (GetFullClassName (typeNode) =3D=3D "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 =3D new XmlDocument ();
string ns =3D (string) de.Key;
- =09
ArrayList list =3D (ArrayList) de.Value;
- list.Sort();
-
- XmlElement elements =3D doc.CreateElement ("elements");
- doc.AppendChild (elements);
+ list.Sort ();
=09
- string file =3D "xml.summary." + ns;
Console.Error.WriteLine ("Have {0} elements in the {1}", list.Count, ns=
);
+ =09
+ XmlTextWriter w =3D hs.PackXmlWriter ("xml.summary." + ns);
+ =09
+ w.WriteStartElement ("elements");
+
foreach (TypeInfo p in list){
- XmlElement e =3D null;
- =09
switch (p.type_kind){
case "Class":
- e =3D doc.CreateElement ("class");=20
+ w.WriteStartElement ("class");=20
break;
=09
case "Enumeration":
- e =3D doc.CreateElement ("enum");
+ w.WriteStartElement ("enum");
break;
=09
case "Structure":
- e =3D doc.CreateElement ("struct");
+ w.WriteStartElement ("struct");
break;
=09
case "Delegate":
- e =3D doc.CreateElement ("delegate");
+ w.WriteStartElement ("delegate");
break;
=09
case "Interface":
- e =3D doc.CreateElement ("interface");
+ w.WriteStartElement ("interface");
break;
}
- =09
- e.SetAttribute ("name", p.type_name);
- e.SetAttribute ("fullname", p.type_full);
- e.SetAttribute ("assembly", p.type_assembly);
- XmlNode copy =3D 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);
+ =09
+ w.WriteEndDocument();
}
}
=20
static Hashtable class_summaries =3D new Hashtable ();
=20
- XmlDocument doc;
+ XmlNode typeNode;
=09
void PopulateClass (string ns, Node ns_node, string file)
{
- doc =3D new XmlDocument ();
+ XmlDocument doc =3D new XmlDocument ();
doc.Load (file);
=09
- string name =3D EcmaDoc.GetClassName (doc);
- string assembly =3D EcmaDoc.GetClassAssembly (doc);
- string kind =3D EcmaDoc.GetTypeKind (doc);
- string full =3D EcmaDoc.GetFullClassName (doc);
+ typeNode =3D doc.SelectSingleNode ("/Type");
+ =09
+ string name =3D EcmaDoc.GetClassName (typeNode);
+ string assembly =3D EcmaDoc.GetClassAssembly (typeNode);
+ string kind =3D EcmaDoc.GetTypeKind (typeNode);
+ string full =3D EcmaDoc.GetFullClassName (typeNode);
=20
Node class_node;
string file_code =3D ns_node.tree.HelpSource.PackFile (file);
=20
- XmlNode class_summary =3D doc.SelectSingleNode ("/Type/Docs/summary");
+ XmlNode class_summary =3D typeNode.SelectSingleNode ("Docs/summary");
ArrayList l =3D (ArrayList) class_summaries [ns];
if (l =3D=3D null)
l =3D class_summaries [ns] =3D new ArrayList ();
@@ -316,7 +315,7 @@
//
void PopulateMember (string typename, Node node, string text, string plur=
al_text)
{
- XmlNodeList list =3D doc.SelectNodes (String.Format ("/Type/Members/Memb=
er[MemberType=3D\"{0}\"]", text));
+ XmlNodeList list =3D typeNode.SelectNodes (String.Format ("Members/Membe=
r[MemberType=3D\"{0}\"]", text));
int count =3D list.Count;
=09
if (count =3D=3D 0)
Index: provider.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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 @@
=20
return entry_name;
}
-=09
- public void PackXml (string fname, XmlDocument doc)
+ =09
+ public System.Xml.XmlTextWriter PackXmlWriter (string entry_name)
{
- doc.Save ("tmp");
- PackFile ("tmp", fname);
+ ZipEntry entry =3D new ZipEntry (entry_name);
+ zip_output.PutNextEntry (entry);
+ return new System.Xml.XmlTextWriter (zip_output, null);
}
=09
public virtual string GetText (string url, out Node n)
--=-enAtDK22+JYv7Jn4N0GI--