[gnome-menus/wip/gobject: 1/15] DesktopEntry: Make basename const reference
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-menus/wip/gobject: 1/15] DesktopEntry: Make basename const reference
- Date: Sun, 17 Apr 2011 14:00:28 +0000 (UTC)
commit db5f56abb5c9d688b2ab5d111527bd0bc621fe8e
Author: Colin Walters <walters verbum org>
Date: Sat Apr 16 11:04:26 2011 -0400
DesktopEntry: Make basename const reference
Avoids another malloc block.
https://bugzilla.gnome.org/show_bug.cgi?id=647968
libmenu/desktop-entries.c | 26 ++++++++++++++++++++------
1 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/libmenu/desktop-entries.c b/libmenu/desktop-entries.c
index 28d0106..07a1558 100644
--- a/libmenu/desktop-entries.c
+++ b/libmenu/desktop-entries.c
@@ -39,7 +39,7 @@ enum
struct DesktopEntry
{
char *path;
- char *basename;
+ const char *basename;
GQuark *categories;
@@ -66,6 +66,23 @@ struct DesktopEntrySet
* Desktop entries
*/
+/**
+ * unix_basename_from_path:
+ * @path: Path string
+ *
+ * Returns: A constant pointer into the basename of @path
+ */
+static const char *
+unix_basename_from_path (const char *path)
+{
+ const char *basename = g_strrstr (path, "/");
+ if (basename)
+ return basename + 1;
+ else
+ return path;
+}
+
+
static guint
get_flags_from_key_file (DesktopEntry *entry,
GKeyFile *key_file,
@@ -349,8 +366,8 @@ desktop_entry_new (const char *path)
retval->refcount = 1;
retval->type = type;
- retval->basename = g_path_get_basename (path);
retval->path = g_strdup (path);
+ retval->basename = unix_basename_from_path (retval->path);
return desktop_entry_load (retval);
}
@@ -413,8 +430,8 @@ desktop_entry_copy (DesktopEntry *entry)
retval->refcount = 1;
retval->type = entry->type;
- retval->basename = g_strdup (entry->basename);
retval->path = g_strdup (entry->path);
+ retval->basename = unix_basename_from_path (retval->path);
retval->name = g_strdup (entry->name);
retval->generic_name = g_strdup (entry->generic_name);
retval->full_name = g_strdup (entry->full_name);
@@ -472,9 +489,6 @@ desktop_entry_unref (DesktopEntry *entry)
g_free (entry->exec);
entry->exec = NULL;
- g_free (entry->basename);
- entry->basename = NULL;
-
g_free (entry->path);
entry->path = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]