Use per-rpmfi string cache for file capability strings
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 5 Feb 2009 20:37:27 +0000 (22:37 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 5 Feb 2009 20:37:27 +0000 (22:37 +0200)
- most packages wont have file capabilities attached at all, and even
  where present, the files with capabilities are likely to be few and
  far in between, avoid wasting memory

lib/rpmfi.c
lib/rpmfi_internal.h

index 4b34763..2720172 100644 (file)
@@ -457,7 +457,7 @@ const char * rpmfiFCapsIndex(rpmfi fi, int ix)
 {
     const char *fcaps = NULL;
     if (fi != NULL && ix >= 0 && ix < fi->fc) {
-       fcaps = fi->fcaps ? fi->fcaps[ix] : "";
+       fcaps = fi->fcapcache ? strcacheGet(fi->fcapcache, fi->fcaps[ix]) : "";
     }
     return fcaps;
 }
@@ -1069,6 +1069,7 @@ fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, fi->Type, fi->fc);
        fi->flinks = _free(fi->flinks);
        fi->flangs = _free(fi->flangs);
        fi->digests = _free(fi->digests);
+       fi->fcapcache = strcacheFree(fi->fcapcache);
        fi->fcaps = _free(fi->fcaps);
 
        fi->cdict = _free(fi->cdict);
@@ -1216,8 +1217,10 @@ rpmfi rpmfiNew(const rpmts ts, Header h, rpmTag tagN, rpmfiFlags flags)
     if (!(flags & RPMFI_NOFILESTATES))
        _hgfi(h, RPMTAG_FILESTATES, &td, defFlags, fi->fstates);
 
-    if (!(flags & RPMFI_NOFILECAPS))
-       _hgfi(h, RPMTAG_FILECAPS, &td, defFlags, fi->fcaps);
+    if (!(flags & RPMFI_NOFILECAPS)) {
+       fi->fcapcache = strcacheNew();
+       fi->fcaps = cacheTag(fi->fcapcache, h, RPMTAG_FILECAPS);
+    }
 
     if (!(flags & RPMFI_NOFILELINKTOS)) {
        fi->flinkcache = strcacheNew();
index 06de2aa..c918def 100644 (file)
@@ -54,7 +54,8 @@ struct rpmfi_s {
     char * fstates;            /*!< File state(s) (from header) */
 
     const rpm_color_t * fcolors;/*!< File color bits (header) */
-    const char ** fcaps;       /*! File capabilities (header) */
+    strcache fcapcache;                /*!< File capabilities cache */
+    scidx_t * fcaps;           /*!< Index to file cap(s) cache */
 
     const char ** cdict;       /*!< File class dictionary (header) */
     rpm_count_t ncdict;                /*!< No. of class entries. */