From 07ee8fd6a42aaf4b9f97972700db9da0aee895ce Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 7 Nov 2008 15:20:35 +0100 Subject: [PATCH 1/1] screen_file: optimized title formula Don't allocate and copy memory. --- src/screen_file.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/screen_file.c b/src/screen_file.c index 5a81e8f..75e4d16 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -176,21 +176,19 @@ browse_open(mpd_unused mpdclient_t *c) static const char * browse_title(char *str, size_t size) { - char *dirname, *parentdir; + const char *path = NULL, *prev = NULL, *slash = browser.filelist->path; - dirname = g_path_get_dirname(browser.filelist->path); - parentdir = g_path_get_basename(dirname); - - if( parentdir[0] == '.' && strlen(parentdir) == 1 ) { - parentdir = NULL; + /* determine the last 2 parts of the path */ + while ((slash = strchr(slash, '/')) != NULL) { + path = prev; + prev = ++slash; } - g_snprintf(str, size, _("Browse: %s%s%s"), - parentdir ? parentdir : "", - parentdir ? "/" : "", - g_basename(browser.filelist->path)); - free(dirname); - free(parentdir); + if (path == NULL) + /* fall back to full path */ + path = browser.filelist->path; + + g_snprintf(str, size, _("Browse: %s"), path); return str; } -- 2.30.2