diff options
author | Maarten Bosmans <mkbosmans@gmail.com> | 2009-12-28 22:10:00 +0100 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2010-01-04 10:01:46 +0100 |
commit | 21ad48628ecf5b68d88aed04d91ef8cbdf1830c0 (patch) | |
tree | dbaf26cc68d272adefbba4a6eb026ddc6968abad | |
parent | 7a1154182baf1742a4a08db0120b50cc27d7e7e8 (diff) |
Load cache on Application.Init, some more tweaks
-rw-r--r-- | gstreamer-sharp/Application.cs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/gstreamer-sharp/Application.cs b/gstreamer-sharp/Application.cs index b365a74..c7468de 100644 --- a/gstreamer-sharp/Application.cs +++ b/gstreamer-sharp/Application.cs @@ -62,24 +62,24 @@ namespace Gst { private static Dictionary<string,Type> TypeCache = new Dictionary<string,Type> (); // Recursively check for types with GTypeNameAttribute and put them in TypeCache, - // but only gstreamer-sharp is in the chain of referenced assemblies. - private static bool PutAssemblyTypesInCache (Assembly asm) + // but only if gstreamer-sharp is in the chain of referenced assemblies. + private static void PutAssemblyTypesInCache (Assembly asm) { - bool result; - // If already visited, return immediately - if (AssemblyTypesInCache.TryGetValue(asm.GetHashCode (), out result)) - return result; + if (AssemblyTypesInCache.ContainsKey(asm.GetHashCode ())) + return; - result = false; + // Add with false to avoid chasing circular dependencies AssemblyTypesInCache.Add (asm.GetHashCode (), false); // Result is true for gstreamer-sharp or if a referenced assembly results in true - if (asm.GetName().Name == "gstreamer-sharp") - result = true; + bool result = asm.GetName().Name.Equals("gstreamer-sharp"); + foreach (AssemblyName ref_name in asm.GetReferencedAssemblies ()) { try { - result = result | PutAssemblyTypesInCache (Assembly.Load (ref_name)); + Assembly ref_asm = Assembly.Load (ref_name); + PutAssemblyTypesInCache (ref_asm); + result = result | AssemblyTypesInCache[ref_asm.GetHashCode ()]; } catch { /* Failure to load a referenced assembly is not an error */ } @@ -101,16 +101,11 @@ namespace Gst { } } } - - return result; } private static System.Type GstResolveType (Gst.GLib.GType gtype, string gtype_name) { - // Make sure all loaded assemblies are in the TypeCache - Assembly[] assemblies = (Assembly[]) AppDomain.CurrentDomain.GetAssemblies ().Clone (); - foreach (Assembly asm in assemblies) { - PutAssemblyTypesInCache (asm); - } + // Make sure all currently loaded assemblies are in the TypeCache + System.Array.ForEach((Assembly[]) AppDomain.CurrentDomain.GetAssemblies ().Clone (), Application.PutAssemblyTypesInCache); // Return the managed type if (TypeCache.ContainsKey (gtype_name)) @@ -120,6 +115,8 @@ namespace Gst { } private static void RegisterManagedTypes() { + // Load types in TypeCache to speed up later invocations of GstResolveType + System.Array.ForEach((Assembly[]) AppDomain.CurrentDomain.GetAssemblies ().Clone (), Application.PutAssemblyTypesInCache); Gst.GLib.GType.ResolveType += GstResolveType; Gst.GLib.GType.Register (Fraction.GType, typeof (Fraction)); |