poldek: poldek/pkgdir/pkgdir_dirindex.c, poldek/pkg.c, poldek/libp...

mis mis at pld-linux.org
Sat Jun 30 14:01:48 CEST 2007


Author: mis                          Date: Sat Jun 30 12:01:48 2007 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- do not bsearch on unsorted array (#34)

---- Files affected:
poldek/poldek/pkgdir:
   pkgdir_dirindex.c (1.13 -> 1.14) 
poldek/poldek:
   pkg.c (1.115 -> 1.116) , libpoldek.sym (1.28 -> 1.29) , capreq.h (1.30 -> 1.31) , capreq.c (1.44 -> 1.45) 

---- Diffs:

================================================================
Index: poldek/poldek/pkgdir/pkgdir_dirindex.c
diff -u poldek/poldek/pkgdir/pkgdir_dirindex.c:1.13 poldek/poldek/pkgdir/pkgdir_dirindex.c:1.14
--- poldek/poldek/pkgdir/pkgdir_dirindex.c:1.13	Mon Jun 25 00:47:27 2007
+++ poldek/poldek/pkgdir/pkgdir_dirindex.c	Sat Jun 30 14:01:43 2007
@@ -505,7 +505,7 @@
 {
     const char **tl, **tl_save;
     char val[16 * 1024];
-    int  vlen, n = 0, nadded = 0;
+    int  vlen, n = 0, nadded = 0, created_here = 0;
 
     n_assert(key[1] == PREFIX_PKGKEY_REQDIR);
     vlen = sizeof(val);
@@ -513,15 +513,15 @@
     if (tl == NULL)
         return 0;
     
-    if (!pkg->reqs)
+    if (!pkg->reqs) {
         pkg->reqs = capreq_arr_new(n);
-        
+        created_here = 1;
+    }
+    
     while (*tl) {
         const char *dir = *tl;
         
-        if (*dir && !n_array_bsearch_ex(pkg->reqs, dir,
-                                        (tn_fn_cmp)capreq_cmp2name)) {
-            
+        if (*dir && (created_here || !capreq_arr_contains(pkg->reqs, dir))) {
             struct capreq *req = capreq_new(pkg->na, dir, 0, NULL, NULL, 0,
                                             CAPREQ_BASTARD);
             n_array_push(pkg->reqs, req);

================================================================
Index: poldek/poldek/pkg.c
diff -u poldek/poldek/pkg.c:1.115 poldek/poldek/pkg.c:1.116
--- poldek/poldek/pkg.c:1.115	Thu Jun 21 18:47:45 2007
+++ poldek/poldek/pkg.c	Sat Jun 30 14:01:43 2007
@@ -920,8 +920,7 @@
     struct capreq *cnfl = NULL;
 
     DBGF("%s %s%s", pkg_id(pkg), pkg_id(cpkg), isbastard ? " (bastard)" : "");
-    if (n_array_bsearch_ex(pkg->cnfls, cpkg->name,
-                           (tn_fn_cmp)capreq_cmp2name) == NULL) {
+    if (!capreq_arr_contains(pkg->cnfls, cpkg->name)) {
         cnfl = capreq_new(pkg->na, cpkg->name, cpkg->epoch, cpkg->ver,
                           cpkg->rel, REL_EQ,
                           (isbastard ? CAPREQ_BASTARD : 0));
@@ -935,8 +934,7 @@
 
 int pkg_has_pkgcnfl(struct pkg *pkg, struct pkg *cpkg)
 {
-    return pkg->cnfls && (n_array_bsearch_ex(pkg->cnfls, cpkg->name,
-                                             (tn_fn_cmp)capreq_cmp2name));
+    return pkg->cnfls && capreq_arr_contains(pkg->cnfls, cpkg->name);
 }
 
 struct pkguinf *pkg_xuinf(const struct pkg *pkg, tn_array *langs) 

================================================================
Index: poldek/poldek/libpoldek.sym
diff -u poldek/poldek/libpoldek.sym:1.28 poldek/poldek/libpoldek.sym:1.29
--- poldek/poldek/libpoldek.sym:1.28	Fri Jun 29 00:28:21 2007
+++ poldek/poldek/libpoldek.sym	Sat Jun 30 14:01:43 2007
@@ -20,7 +20,6 @@
 capreq_arr_store
 capreq_arr_store_n
 capreq_clone
-capreq_cmp2name
 capreq_cmp_name
 capreq_cmp_name_evr
 capreq_epoch_

================================================================
Index: poldek/poldek/capreq.h
diff -u poldek/poldek/capreq.h:1.30 poldek/poldek/capreq.h:1.31
--- poldek/poldek/capreq.h:1.30	Fri Jun 22 00:29:49 2007
+++ poldek/poldek/capreq.h	Sat Jun 30 14:01:43 2007
@@ -117,12 +117,12 @@
 int capreq_strcmp_name_evr(struct capreq *pr1, struct capreq *pr2);
 
 int capreq_cmp_name(struct capreq *cr1, struct capreq *cr2);
-int capreq_cmp2name(struct capreq *pr1, const char *name);
 int capreq_cmp_name_evr(struct capreq *cr1, struct capreq *cr2);
 
 #ifndef SWIG
 tn_array *capreq_arr_new(int size);
-int capreq_arr_find(tn_array *capreqs, const char *name);
+int capreq_arr_find(tn_array *capreqs, const char *name); /* returns index */
+int capreq_arr_contains(tn_array *capreqs, const char *name); /* returns bool */
 tn_buf *capreq_arr_join(tn_array *capreqs, tn_buf *nbuf, const char *sep);
 
 int capreq_arr_store_n(tn_array *arr);

================================================================
Index: poldek/poldek/capreq.c
diff -u poldek/poldek/capreq.c:1.44 poldek/poldek/capreq.c:1.45
--- poldek/poldek/capreq.c:1.44	Thu Jun 21 18:47:45 2007
+++ poldek/poldek/capreq.c	Sat Jun 30 14:01:43 2007
@@ -59,7 +59,7 @@
     return strcmp(capreq_name(cr1), capreq_name(cr2));
 }
 
-__inline__
+__inline__ static
 int capreq_cmp2name(struct capreq *cr1, const char *name)
 {
     return strcmp(capreq_name(cr1), name);
@@ -427,9 +427,24 @@
 __inline__
 int capreq_arr_find(tn_array *capreqs, const char *name)
 {
+    /* capreq_cmp2name is compilant with capreq_cmp_name_evr */
+    if (!n_array_is_sorted(capreqs))
+        n_array_sort(capreqs);  
+    
     return n_array_bsearch_idx_ex(capreqs, name,
                                   (tn_fn_cmp)capreq_cmp2name);
 }
+
+__inline__
+int capreq_arr_contains(tn_array *capreqs, const char *name)
+{
+    if (!n_array_is_sorted(capreqs))
+        n_array_sort(capreqs);  /* capreq_cmp2name */
+    
+    return n_array_bsearch_idx_ex(capreqs, name,
+                                  (tn_fn_cmp)capreq_cmp2name) > -1;
+}
+
 
 tn_buf *capreq_arr_join(tn_array *capreqs, tn_buf *nbuf, const char *sep)
 {
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/poldek/poldek/pkgdir/pkgdir_dirindex.c?r1=1.13&r2=1.14&f=u
    http://cvs.pld-linux.org/poldek/poldek/pkg.c?r1=1.115&r2=1.116&f=u
    http://cvs.pld-linux.org/poldek/poldek/libpoldek.sym?r1=1.28&r2=1.29&f=u
    http://cvs.pld-linux.org/poldek/poldek/capreq.h?r1=1.30&r2=1.31&f=u
    http://cvs.pld-linux.org/poldek/poldek/capreq.c?r1=1.44&r2=1.45&f=u



More information about the pld-cvs-commit mailing list