Gst.Object: Improved performance on multiple property calls

Successful property lookups get cached in a dictionary
to improve performance of subsequent lookups
This commit is contained in:
Stephan Sundermann 2013-10-10 20:45:59 +02:00
parent 4d0a5a796b
commit d4edf8050d

View file

@ -14,6 +14,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace Gst {
@ -22,14 +23,25 @@ namespace Gst {
partial class Object
{
private Dictionary <string, bool> PropertyNameCache = new Dictionary<string, bool> ();
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_object_class_find_property (IntPtr klass, IntPtr name);
bool PropertyExists (string name) {
if (PropertyNameCache.ContainsKey (name))
return PropertyNameCache [name];
var ptr = g_object_class_find_property (GType.GetClassPtr (), GLib.Marshaller.StringToPtrGStrdup (name));
var result = ptr != IntPtr.Zero;
GLib.Marshaller.Free (ptr);
// just cache the positive results because there might
// actually be new properties getting installed
if (result)
PropertyNameCache [name] = result;
return result;
}