generator: Use a Dictionary to hold the class structs cache
Again, nicer generated code, and no impact outside of it.
This commit is contained in:
parent
3d6decbd0d
commit
eddc5fa796
1 changed files with 4 additions and 4 deletions
|
@ -316,15 +316,15 @@ namespace GtkSharp.Generation {
|
|||
sw.WriteLine ("\t\tstatic uint class_offset = 0;");
|
||||
else
|
||||
sw.WriteLine ("\t\tstatic uint class_offset = ((GLib.GType) typeof ({0})).GetClassSize ();", cs_parent);
|
||||
sw.WriteLine ("\t\tstatic Hashtable class_structs;");
|
||||
sw.WriteLine ("\t\tstatic Dictionary<GLib.GType, {0}> class_structs;", class_struct_name);
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\tstatic {0} GetClassStruct (GLib.GType gtype, bool use_cache)", class_struct_name);
|
||||
sw.WriteLine ("\t\t{");
|
||||
sw.WriteLine ("\t\t\tif (class_structs == null)");
|
||||
sw.WriteLine ("\t\t\t\tclass_structs = new Hashtable ();");
|
||||
sw.WriteLine ("\t\t\t\tclass_structs = new Dictionary<GLib.GType, {0}> ();", class_struct_name);
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\t\tif (use_cache && class_structs.Contains (gtype))");
|
||||
sw.WriteLine ("\t\t\t\treturn ({0}) class_structs [gtype];", class_struct_name);
|
||||
sw.WriteLine ("\t\t\tif (use_cache && class_structs.ContainsKey (gtype))");
|
||||
sw.WriteLine ("\t\t\t\treturn class_structs [gtype];");
|
||||
sw.WriteLine ("\t\t\telse {");
|
||||
sw.WriteLine ("\t\t\t\tIntPtr class_ptr = new IntPtr (gtype.GetClassPtr ().ToInt64 () + class_offset);");
|
||||
sw.WriteLine ("\t\t\t\t{0} class_struct = ({0}) Marshal.PtrToStructure (class_ptr, typeof ({0}));", class_struct_name);
|
||||
|
|
Loading…
Reference in a new issue