socsvn commit: r254178 - in soc2013/mattbw/backend: . actions

mattbw at FreeBSD.org mattbw at FreeBSD.org
Fri Jul 5 20:17:07 UTC 2013


Author: mattbw
Date: Fri Jul  5 20:17:06 2013
New Revision: 254178
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254178

Log:
  use sbufs instead of GLib for composing the filename list

Modified:
  soc2013/mattbw/backend/actions/get-files.c
  soc2013/mattbw/backend/hash_traverse.h
  soc2013/mattbw/backend/utils.c
  soc2013/mattbw/backend/utils.h

Modified: soc2013/mattbw/backend/actions/get-files.c
==============================================================================
--- soc2013/mattbw/backend/actions/get-files.c	Fri Jul  5 19:57:40 2013	(r254177)
+++ soc2013/mattbw/backend/actions/get-files.c	Fri Jul  5 20:17:06 2013	(r254178)
@@ -19,6 +19,8 @@
  */
 
 #include <glib.h>
+#include <sys/sbuf.h>
+
 #include "../pk-backend.h"
 #include "pkg.h"
 
@@ -63,34 +65,29 @@
 {
 	struct pkg_file *file;
 	int		err;
+	int		sb_err;
+	struct sbuf *sb;
 
-	gchar         **filenames;
-	gchar          *joined_filenames;
-	gint		capacity;
-	gint		i;
-
-	/*
-	 * Start off with a small array to hold the file names, and expand it
-	 * if needs be.
-	 */
-	capacity = FILE_NAME_STEP;
-	i = 0;
-	file = NULL;
-	filenames = g_new(gchar *, capacity);
-	for (HASH_FOR(err, pkg_files, pkg, &file)) {
-		/* Out of capacity (leaving a NULL)?  Expand the array. */
-		if (i >= (capacity - 1)) {
-			capacity += FILE_NAME_STEP;
-			filenames = g_renew(gchar *, filenames, capacity);
-		}
-		filenames[i] = g_strdup(pkg_file_path(file));
-		i++;
+	/* Construct a string of the form ";file1;file2;file3;...".
+	 * We'll get rid of the initial ; later.
+ 	 */
+	sb = sbuf_new_auto();
+	for (HASH_FOR(err, pkg_files, pkg, &file))
+		sbuf_printf(sb, ";%s", pkg_file_path(file));
+	sb_err = sbuf_finish(sb);
+	if (sb_err)
+		pk_backend_error_code(query_backend(q),
+			PK_ERROR_ENUM_INTERNAL_ERROR,
+			"couldn't construct filename string");
+	else {
+		char *filenames;
+
+		filenames = sbuf_data(sb);
+		/* Skip over any initial ;*/
+		if (filenames[0] == ';')
+			filenames++;
+		
+		pk_backend_files(query_backend(q), id, filenames);
 	}
-	filenames[i] = NULL;
-
-	joined_filenames = g_strjoinv(";", filenames);
-	g_strfreev(filenames);
-
-	pk_backend_files(query_backend(q), id, joined_filenames);
-	g_free(joined_filenames);
+	sbuf_delete(sb);
 }

Modified: soc2013/mattbw/backend/hash_traverse.h
==============================================================================
--- soc2013/mattbw/backend/hash_traverse.h	Fri Jul  5 19:57:40 2013	(r254177)
+++ soc2013/mattbw/backend/hash_traverse.h	Fri Jul  5 20:17:06 2013	(r254178)
@@ -21,7 +21,8 @@
 #ifndef _PKGNG_BACKEND_HASH_TRAVERSE_H_
 #define _PKGNG_BACKEND_HASH_TRAVERSE_H_
 
+/* for loop body for pkgng iterators. */
 #define HASH_FOR(err, hash, ...) \
 	(err) = hash(__VA_ARGS__); (err) == EPKG_OK; (err) = hash(__VA_ARGS__)
- 
+
 #endif /* !_PKGNG_BACKEND_HASH_TRAVERSE_H_ */

Modified: soc2013/mattbw/backend/utils.c
==============================================================================
--- soc2013/mattbw/backend/utils.c	Fri Jul  5 19:57:40 2013	(r254177)
+++ soc2013/mattbw/backend/utils.c	Fri Jul  5 20:17:06 2013	(r254178)
@@ -78,8 +78,8 @@
 
 /*
  * Checks two strings with strcmp and emits TRUE if they match. If either
- * string is NULL or empty, emit TRUE as well (this is so that missing PackageID
- * elements trigger matches).
+ * string is NULL or empty, emit TRUE as well (this is so that missing
+ * PackageID elements trigger matches).
  */
 gboolean
 string_match(const char *left, const char *right)

Modified: soc2013/mattbw/backend/utils.h
==============================================================================
--- soc2013/mattbw/backend/utils.h	Fri Jul  5 19:57:40 2013	(r254177)
+++ soc2013/mattbw/backend/utils.h	Fri Jul  5 20:17:06 2013	(r254178)
@@ -36,5 +36,4 @@
 	 const char **data_p);
 gboolean	string_match(const char *left, const char *right);
 
-
 #endif				/* !_PKGNG_BACKEND_DETAILS_H_ */


More information about the svn-soc-all mailing list