[tracker/tracker-0.12: 159/202] tracker-extract: Use g_strchug() functionality to avoid allocating memory



commit 7e343e787262ef345585dc7bd29cca813b4f871d
Author: Martyn Russell <martyn lanedo com>
Date:   Thu Sep 29 17:41:31 2011 +0100

    tracker-extract: Use g_strchug() functionality to avoid allocating memory
    
    Previously the work from Sam just returned buffer and the returned string
    required a +9 to get past the cuesheet=, however, I thought it better to
    just move the memory in a similar way to g_strchug() so we don't allocated any
    memory and the returned value can be used straight away.

 src/tracker-extract/tracker-extract-gstreamer.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index bb29738..9091939 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -383,16 +383,21 @@ get_embedded_cue_sheet_data (GstTagList *tag_list)
 		gst_tag_list_get_string_index (tag_list, GST_TAG_EXTENDED_COMMENT, i, &buffer);
 
 		if (g_ascii_strncasecmp (buffer, "cuesheet=", 9) == 0) {
-			gchar *result;
-
-			result = g_strdup (buffer + 9);
-			g_free (buffer);
+			/* Use same functionality as g_strchug() here
+			 * for cuesheet, to avoid allocating new
+			 * memory but also to return the string and
+			 * not have to jump past cuesheet= on the
+			 * returned value.
+			 */
+			g_memmove (buffer, buffer + 9, strlen ((gchar *) buffer + 9) + 1);
 
-			return result;
+			return buffer;
 		}
 
 		g_free (buffer);
 	}
+
+	return NULL;
 }
 
 static gboolean



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