From 9eb479aeefba7310b105c57aa3e970940713d6d9 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 11 Sep 2013 09:48:51 +0100 Subject: [PATCH] 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 file changed, 5 insertions(+), 3 deletions(-) diff --git a/clutter/evdev/clutter-device-manager-evdev.c b/clutter/evdev/clutter-device-manager-evdev.c index 9fa774b4e..08c3e1579 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; }