diff --git a/rpm-4_0.spec b/rpm-4_0.spec index c40223c..6f35b46 100644 --- a/rpm-4_0.spec +++ b/rpm-4_0.spec @@ -4,7 +4,7 @@ Name: %rpm_name Version: %rpm_version -Release: alt95.M41.18 +Release: alt95.M41.19 %define ifdef() %if %{expand:%%{?%{1}:1}%%{!?%{1}:0}} %define get_dep() %(rpm -q --qf '%%{NAME} >= %%|SERIAL?{%%{SERIAL}:}|%%{VERSION}-%%{RELEASE}' %1 2>/dev/null || echo '%1 >= unknown') @@ -528,6 +528,9 @@ fi %endif #with contrib %changelog +* Sat Jun 13 2009 Alexey Tourbin 4.0.4-alt95.M41.19 +- rpmdb: Minor fingerprint cache improvement. + * Sun May 10 2009 Alexey Tourbin 4.0.4-alt95.M41.18 - package.c (readPackageHeaders): Use posix_fadvise(2) to disable readahead. When scanning a large number of packages (with e.g. rpmquery), readahead diff --git a/rpmdb/fprint.c b/rpmdb/fprint.c index 3af0118..673c3e7 100644 --- a/rpmdb/fprint.c +++ b/rpmdb/fprint.c @@ -10,21 +10,24 @@ #include "fprint.h" #include "debug.h" +#include "rpmhash.h" #include "jhash.h" +struct fprintCache_s { + hashTable dn2de; /*!< maps dirName to fprintCacheEntry */ +}; + fingerPrintCache fpCacheCreate(unsigned int size) { - fingerPrintCache fpc; - - fpc = xmalloc(sizeof(*fpc)); - fpc->ht = htCreate(size, hashFunctionString, hashEqualityString); + fingerPrintCache fpc = xmalloc(sizeof(*fpc)); + fpc->dn2de = htCreate(size, hashFunctionString, hashEqualityString); return fpc; } fingerPrintCache fpCacheFree(fingerPrintCache cache) { - /* don't free keys: key=dirname is part of value=entry, see below */ - cache->ht = htFree(cache->ht, NULL, _free); + /* don't free keys: key=dirname is flexible member of value=entry */ + cache->dn2de = htFree(cache->dn2de, NULL, _free); cache = _free(cache); return NULL; } @@ -42,7 +45,7 @@ static /*@null@*/ const struct fprintCacheEntry_s * cacheContainsDirectory( { const void ** data; - if (htGetEntry(cache->ht, dirName, &data, NULL, NULL)) + if (htGetEntry(cache->dn2de, dirName, &data, NULL, NULL)) return NULL; return data[0]; } @@ -131,22 +134,16 @@ static fingerPrint doLookup(fingerPrintCache cache, if (cacheHit != NULL) { fp.entry = cacheHit; } else if (!stat((*buf != '\0' ? buf : "/"), &sb)) { - /* single malloc for both key=dirname and value=entry */ - size_t nb = sizeof(*fp.entry) + (*buf != '\0' ? (end-buf) : 1) + 1; - struct fprintCacheEntry_s *newEntry = xmalloc(nb); + /* dirName has a byte for terminating '\0' */ + size_t nb = sizeof(*fp.entry) + (*buf != '\0' ? (end-buf) : 1); + struct fprintCacheEntry_s *de = xmalloc(nb); - /*@-usereleased@*/ /* LCL: contiguous malloc confusion */ - char *dn = (char *)(newEntry + 1); - strcpy(dn, (*buf != '\0' ? buf : "/")); - newEntry->ino = sb.st_ino; - newEntry->dev = sb.st_dev; - newEntry->dirName = dn; - fp.entry = newEntry; + de->ino = sb.st_ino; + de->dev = sb.st_dev; + strcpy(de->dirName, (*buf != '\0' ? buf : "/")); - /*@-kepttrans -dependenttrans @*/ - htAddEntry(cache->ht, dn, fp.entry); - /*@=kepttrans =dependenttrans @*/ - /*@=usereleased@*/ + htAddEntry(cache->dn2de, de->dirName, de); + fp.entry = de; } if (fp.entry) { diff --git a/rpmdb/fprint.h b/rpmdb/fprint.h index e52a59d..25c07fa 100644 --- a/rpmdb/fprint.h +++ b/rpmdb/fprint.h @@ -6,10 +6,8 @@ * Identify a file name path by a unique "finger print". */ -#include "rpmhash.h" -#include "header.h" - /** + * Finger print cache. */ typedef /*@abstract@*/ struct fprintCache_s * fingerPrintCache; @@ -25,16 +23,9 @@ typedef struct fingerPrint_s fingerPrint; * installs of a system w/o actually mounting filesystems. */ struct fprintCacheEntry_s { - const char * dirName; /*!< path to existing directory */ dev_t dev; /*!< stat(2) device number */ ino_t ino; /*!< stat(2) inode number */ -}; - -/** - * Finger print cache. - */ -struct fprintCache_s { - hashTable ht; /*!< hashed by dirName */ + char dirName[1]; /*!< path to existing directory */ }; /**