[pacman-dev] One liner alpm_pkg_find

Nagy Gabor ngaba at bibl.u-szeged.hu
Mon Apr 21 07:30:57 EDT 2008


From 60e9d311b05f9d5e1d4d63476eb00ec85077e965 Mon Sep 17 00:00:00 2001
From: Nagy Gabor <ngaba at bibl.u-szeged.hu>
Date: Mon, 21 Apr 2008 13:29:01 +0200
Subject: [PATCH] One liner alpm_pkg_find

This patch kills some code duplication.
Note: There was a little confusion between alpm_list_remove's and alpm_list_find's compare functions.

Signed-off-by: Nagy Gabor <ngaba at bibl.u-szeged.hu>
---
 lib/libalpm/alpm_list.c |    2 +-
 lib/libalpm/db.c        |    2 +-
 lib/libalpm/deps.c      |    2 +-
 lib/libalpm/package.c   |   16 +---------------
 4 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index ae54e19..ecfef25 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -577,7 +577,7 @@ void SYMEXPORT *alpm_list_find(const alpm_list_t *haystack, const void *needle,
 {
 	const alpm_list_t *lp = haystack;
 	while(lp) {
-		if(lp->data && fn(lp->data, needle) == 0) {
+		if(lp->data && fn(needle, lp->data) == 0) {
 			return(lp->data);
 		}
 		lp = lp->next;
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 6847415..c05f465 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -632,7 +632,7 @@ pmdb_t *_alpm_db_register_sync(const char *treename)
  *
  * @return "provision.name" == needle (as string)
  */
-int _alpm_prov_cmp(const void *provision, const void *needle)
+int _alpm_prov_cmp(const void *needle, const void *provision)
 {
 	char *tmpptr;
 	char *provname = strdup(provision);
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index cec69be..280f2c0 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -196,7 +196,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
 }
 
 /* Little helper function for alpm_list_find */
-static int satisfycmp(const void *pkg, const void *depend)
+static int satisfycmp(const void *depend, const void *pkg)
 {
 	return(!alpm_depcmp((pmpkg_t*) pkg, (pmdepend_t*) depend));
 }
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 1ce0194..8c05c97 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -1108,22 +1108,8 @@ error:
  */
 pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
 {
-	alpm_list_t *lp;
-
 	ALPM_LOG_FUNC;
-
-	if(needle == NULL || haystack == NULL) {
-		return(NULL);
-	}
-
-	for(lp = haystack; lp; lp = lp->next) {
-		pmpkg_t *info = lp->data;
-
-		if(info && strcmp(alpm_pkg_get_name(info), needle) == 0) {
-			return(info);
-		}
-	}
-	return(NULL);
+	return(alpm_list_find(haystack, needle, _alpm_pkgname_pkg_cmp));
 }
 
 /** Test if a package should be ignored.
-- 
1.5.3.8





More information about the pacman-dev mailing list