[mousetweaks] use private variable in object instances



commit 6db1f6aaf24616dca4b3e771f914eeae71c9c607
Author: Gerd Kohlberger <gerdk src gnome org>
Date:   Sun Apr 26 12:43:59 2009 +0200

    use private variable in object instances
    
    Optimization to avoid using the expensive G_TYPE_INSTANCE_GET_PRIVATE
    macro all the time. Additionally there's some minor cleanup to keep
    the coding style consistent.
---
 src/mt-listener.c |   25 ++++++++++---------------
 src/mt-listener.h |   22 ++++++++++------------
 2 files changed, 20 insertions(+), 27 deletions(-)

diff --git a/src/mt-listener.c b/src/mt-listener.c
index 3848ea9..1673c86 100644
--- a/src/mt-listener.c
+++ b/src/mt-listener.c
@@ -18,20 +18,14 @@
  */
 
 #include <glib.h>
-#include <cspi/spi.h>
 
 #include "mt-listener.h"
 
-#define MT_LISTENER_GET_PRIVATE(o) \
-    (G_TYPE_INSTANCE_GET_PRIVATE ((o), MT_TYPE_LISTENER, MtListenerPrivate))
-
-typedef struct _MtListenerPrivate MtListenerPrivate;
 struct _MtListenerPrivate {
     AccessibleEventListener *motion;
     AccessibleEventListener *button;
     AccessibleEventListener *focus;
-
-    Accessible *current_focus;
+    Accessible              *current_focus;
 };
 
 enum {
@@ -56,9 +50,9 @@ G_DEFINE_TYPE (MtListener, mt_listener, G_TYPE_OBJECT)
 static void
 mt_listener_class_init (MtListenerClass *klass)
 {
-    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-    gobject_class->dispose = mt_listener_dispose;
+    object_class->dispose = mt_listener_dispose;
 
     signals[MOTION_EVENT] = 
 	g_signal_new (g_intern_static_string ("motion_event"),
@@ -89,9 +83,11 @@ mt_listener_class_init (MtListenerClass *klass)
 static void
 mt_listener_init (MtListener *listener)
 {
-    MtListenerPrivate *priv = MT_LISTENER_GET_PRIVATE (listener);
+    MtListenerPrivate *priv;
 
-    priv->current_focus = NULL;
+    listener->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (listener,
+							 MT_TYPE_LISTENER,
+							 MtListenerPrivate);
 
     priv->motion = SPI_createAccessibleEventListener (mt_listener_motion_event,
 						      listener);
@@ -110,7 +106,7 @@ mt_listener_init (MtListener *listener)
 static void
 mt_listener_dispose (GObject *object)
 {
-    MtListenerPrivate *priv = MT_LISTENER_GET_PRIVATE (object);
+    MtListenerPrivate *priv = MT_LISTENER (object)->priv;
 
     if (priv->motion) {
 	SPI_deregisterGlobalEventListenerAll (priv->motion);
@@ -147,7 +143,6 @@ mt_event_get_type (void)
     return event;
 }
 
-/* do we need this? */
 MtEvent *
 mt_event_copy (const MtEvent *event)
 {
@@ -188,7 +183,7 @@ mt_listener_button_event (const AccessibleEvent *event, gpointer data)
 static void
 mt_listener_focus_event (const AccessibleEvent *event, gpointer data)
 {
-    MtListenerPrivate *priv = MT_LISTENER_GET_PRIVATE (data);
+    MtListenerPrivate *priv = MT_LISTENER (data)->priv;
 
     if (event->source) {
 	if (priv->current_focus)
@@ -217,5 +212,5 @@ mt_listener_current_focus (MtListener *listener)
 {
     g_return_val_if_fail (MT_IS_LISTENER (listener), NULL);
 
-    return MT_LISTENER_GET_PRIVATE (listener)->current_focus;
+    return listener->priv->current_focus;
 }
diff --git a/src/mt-listener.h b/src/mt-listener.h
index 5451a69..74df20d 100644
--- a/src/mt-listener.h
+++ b/src/mt-listener.h
@@ -33,32 +33,30 @@ G_BEGIN_DECLS
 #define MT_IS_LISTENER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), MT_TYPE_LISTENER))
 #define MT_LISTENER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MT_TYPE_LISTENER, MtListenerClass))
 
-typedef struct _MtListener MtListener;
-typedef struct _MtListenerClass MtListenerClass;
+typedef GObjectClass              MtListenerClass;
+typedef struct _MtListener        MtListener;
+typedef struct _MtListenerPrivate MtListenerPrivate;
 
 struct _MtListener {
-    GObject parent;
-};
-
-struct _MtListenerClass {
-    GObjectClass parent;
+    GObject            parent;
+    MtListenerPrivate *priv;
 };
 
 GType        mt_listener_get_type       (void) G_GNUC_CONST;
 MtListener * mt_listener_get_default    (void);
 Accessible * mt_listener_current_focus  (MtListener *listener);
 
-enum {
+typedef enum {
     EV_MOTION = 0,
     EV_BUTTON_PRESS,
     EV_BUTTON_RELEASE
-};
+} MtEventType;
 
 typedef struct _MtEvent MtEvent;
 struct _MtEvent {
-    gint type;
-    gint x;
-    gint y;
+    MtEventType type;
+    gint        x;
+    gint        y;
 };
 
 GType     mt_event_get_type (void) G_GNUC_CONST;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]