mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-20 21:16:24 +00:00
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:
parent
4d0a5a796b
commit
d4edf8050d
1 changed files with 12 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue