[clutter/clutter-1.16] evdev: Cache the regexp



commit 9eb479aeefba7310b105c57aa3e970940713d6d9
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Sep 11 09:48:51 2013 +0100

    evdev: Cache the regexp
    
    Instead of recreating it for every new device, we can cache the GRegex
    and reuse it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707901

 clutter/evdev/clutter-device-manager-evdev.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/clutter/evdev/clutter-device-manager-evdev.c b/clutter/evdev/clutter-device-manager-evdev.c
index 9fa774b..08c3e15 100644
--- a/clutter/evdev/clutter-device-manager-evdev.c
+++ b/clutter/evdev/clutter-device-manager-evdev.c
@@ -820,13 +820,15 @@ find_source_by_device (ClutterDeviceManagerEvdev *manager,
 static gboolean
 is_evdev (const gchar *sysfs_path)
 {
-  GRegex *regex;
+  static GRegex *regex = NULL;
   gboolean match;
 
-  regex = g_regex_new ("/input[0-9]+/event[0-9]+$", 0, 0, NULL);
+  /* cache the regexp */
+  if (G_UNLIKELY (regex == NULL))
+    regex = g_regex_new ("/input[0-9]+/event[0-9]+$", 0, 0, NULL);
+
   match = g_regex_match (regex, sysfs_path, 0, NULL);
 
-  g_regex_unref (regex);
   return match;
 }
 



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