Dont waste time with argv for rpmfc file names
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 26 Sep 2012 08:31:41 +0000 (11:31 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 26 Sep 2012 08:58:29 +0000 (11:58 +0300)
- argvAdd() gets more and more costly as the number of files increase,
  use a plain old string array where one is called for: the size
  is predetermined (from another argv) and we're just copying the
  strings for internal storage here. We do need to pay a little bit
  more attention to details now though.

build/rpmfc.c

index cd77301..d4d11b8 100644 (file)
@@ -46,7 +46,7 @@ struct rpmfc_s {
 
     rpmfcAttr *atypes; /*!< known file attribute types */
 
-    ARGV_t fn;         /*!< (no. files) file names */
+    char ** fn;                /*!< (no. files) file names */
     ARGV_t *fattrs;    /*!< (no. files) file attribute tokens */
     ARGI_t fcolor;     /*!< (no. files) file colors */
     ARGI_t fcdictx;    /*!< (no. files) file class dictionary indices */
@@ -749,9 +749,11 @@ rpmfc rpmfcFree(rpmfc fc)
            rpmfcAttrFree(*attr);
        free(fc->atypes);
        free(fc->buildRoot);
-       argvFree(fc->fn);
-       for (int i = 0; i < fc->nfiles; i++)
+       for (int i = 0; i < fc->nfiles; i++) {
+           free(fc->fn[i]);
            argvFree(fc->fattrs[i]);
+       }
+       free(fc->fn);
        free(fc->fattrs);
        argiFree(fc->fcolor);
        argiFree(fc->fcdictx);
@@ -811,7 +813,7 @@ rpmRC rpmfcApply(rpmfc fc)
     int ix;
 
     /* Generate package and per-file dependencies. */
-    for (fc->ix = 0; fc->fn != NULL && fc->fn[fc->ix] != NULL; fc->ix++) {
+    for (fc->ix = 0; fc->ix < fc->nfiles && fc->fn[fc->ix] != NULL; fc->ix++) {
        for (ARGV_t fattr = fc->fattrs[fc->ix]; fattr && *fattr; fattr++) {
            rpmfcHelperProvides(fc, *fattr);
            rpmfcHelperRequires(fc, *fattr);
@@ -919,6 +921,7 @@ rpmRC rpmfcClassify(rpmfc fc, ARGV_t argv, rpm_mode_t * fmode)
     }
 
     fc->nfiles = argvCount(argv);
+    fc->fn = xcalloc(fc->nfiles, sizeof(*fc->fn));
     fc->fattrs = xcalloc(fc->nfiles, sizeof(*fc->fattrs));
 
     /* Initialize the per-file dictionary indices. */
@@ -993,7 +996,7 @@ rpmRC rpmfcClassify(rpmfc fc, ARGV_t argv, rpm_mode_t * fmode)
        rpmlog(RPMLOG_DEBUG, "%s: %s\n", s, ftype);
 
        /* Save the path. */
-       argvAdd(&fc->fn, s);
+       fc->fn[fc->ix] = xstrdup(s);
 
        /* Add (filtered) file coloring */
        fcolor |= rpmfcColor(ftype);