[gnome-menus] DesktopEntry: Make basename const reference
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-menus] DesktopEntry: Make basename const reference
- Date: Mon, 1 Aug 2011 17:41:16 +0000 (UTC)
commit ea008b417c02e8238f58d2d419d01129c2de9226
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]