summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2020-02-20 15:24:50 +0100
committerPanu Matilainen <pmatilai@redhat.com>2020-02-24 11:54:22 +0200
commitb2e1b46428ecef15a693a0925641da3565f3e34c (patch)
tree82ea591da93eb6d69b8496983875b5620651a14d
parentc68d858c3d0385a55cc4cc1e91a923356bab8797 (diff)
downloadrpm-b2e1b46428ecef15a693a0925641da3565f3e34c.tar.gz
Switch dependency checking to use pool ids instead of strings
This needs less memory and it should also be faster as the dependencies are already available in id form.
-rw-r--r--lib/depends.c99
1 files changed, 46 insertions, 53 deletions
diff --git a/lib/depends.c b/lib/depends.c
index ab8f7bc1c..1f8c164e1 100644
--- a/lib/depends.c
+++ b/lib/depends.c
@@ -51,8 +51,8 @@ const int rpmFLAGS = RPMSENSE_EQUAL;
#undef HTDATATYPE
#define HASHTYPE filedepHash
-#define HTKEYTYPE const char *
-#define HTDATATYPE const char *
+#define HTKEYTYPE rpmsid
+#define HTDATATYPE rpmsid
#include "rpmhash.H"
#include "rpmhash.C"
#undef HASHTYPE
@@ -60,7 +60,7 @@ const int rpmFLAGS = RPMSENSE_EQUAL;
#undef HTDATATYPE
#define HASHTYPE depexistsHash
-#define HTKEYTYPE const char *
+#define HTKEYTYPE rpmsid
#include "lib/rpmhash.H"
#include "lib/rpmhash.C"
#undef HASHTYPE
@@ -870,33 +870,33 @@ static void checkInstFileDeps(rpmts ts, depCache dcache, rpmte te,
rpmTag depTag, rpmfi fi, int is_not,
filedepHash cache, fingerPrintCache *fpcp)
{
+ rpmstrPool pool = rpmtsPool(ts);
fingerPrintCache fpc = *fpcp;
fingerPrint * fp = NULL;
- const char *basename = rpmfiBN(fi);
- const char *dirname;
- const char **dirnames = 0;
+ rpmsid basename = rpmfiBNId(fi);
+ rpmsid dirname;
+ rpmsid *dirnames = 0;
int ndirnames = 0;
int i;
filedepHashGetEntry(cache, basename, &dirnames, &ndirnames, NULL);
if (!ndirnames)
return;
- dirname = rpmfiDN(fi);
+ dirname = rpmfiDNId(fi);
for (i = 0; i < ndirnames; i++) {
char *fpdep = 0;
const char *dep;
- if (!strcmp(dirnames[i], dirname)) {
+ if (dirnames[i] == dirname) {
dep = rpmfiFN(fi);
} else {
if (!fpc)
- *fpcp = fpc = fpCacheCreate(1001, NULL);
+ *fpcp = fpc = fpCacheCreate(1001, pool);
if (!fp)
- fpLookup(fpc, dirname, basename, &fp);
- if (!fpLookupEquals(fpc, fp, dirnames[i], basename))
+ fpLookupId(fpc, dirname, basename, &fp);
+ if (!fpLookupEqualsId(fpc, fp, dirnames[i], basename))
continue;
- fpdep = rmalloc(strlen(dirnames[i]) + strlen(basename) + 1);
- strcpy(fpdep, dirnames[i]);
- strcat(fpdep, basename);
+ rstrscat(&fpdep, rpmstrPoolStr(pool, dirnames[i]),
+ rpmstrPoolStr(pool, basename), NULL);
dep = fpdep;
}
checkInstDeps(ts, dcache, te, depTag, dep, NULL, is_not);
@@ -905,38 +905,31 @@ static void checkInstFileDeps(rpmts ts, depCache dcache, rpmte te,
_free(fp);
}
-static void addFileDepToHash(filedepHash hash, char *key, size_t keylen)
+static void addFileDepToHash(rpmstrPool pool, filedepHash hash, char *key, size_t keylen)
{
int i;
- char *basename, *dirname;
+ rpmsid basename, dirname;
if (!keylen || key[0] != '/')
return;
for (i = keylen - 1; key[i] != '/'; i--)
;
- dirname = rmalloc(i + 2);
- memcpy(dirname, key, i + 1);
- dirname[i + 1] = 0;
- basename = rmalloc(keylen - i);
- memcpy(basename, key + i + 1, keylen - i - 1);
- basename[keylen - i - 1] = 0;
+ i++; /* include '/' in dirname */
+ dirname = rpmstrPoolIdn(pool, key, i, 1);
+ basename = rpmstrPoolIdn(pool, key + i, keylen - i, 1);
filedepHashAddEntry(hash, basename, dirname);
}
-static void addDepToHash(depexistsHash hash, char *key, size_t keylen)
+static void addDepToHash(rpmstrPool pool, depexistsHash hash, char *key, size_t keylen)
{
- char *keystr;
- if (!keylen)
- return;
- keystr = rmalloc(keylen + 1);
- strncpy(keystr, key, keylen);
- keystr[keylen] = 0;
- depexistsHashAddEntry(hash, keystr);
+ if (keylen)
+ depexistsHashAddEntry(hash, rpmstrPoolIdn(pool, key, keylen, 1));
}
static void addIndexToDepHashes(rpmts ts, rpmDbiTag tag,
depexistsHash dephash, filedepHash filehash,
depexistsHash depnothash, filedepHash filenothash)
{
+ rpmstrPool pool = rpmtsPool(ts);
char *key;
size_t keylen;
rpmdbIndexIterator ii = rpmdbIndexKeyIteratorInit(rpmtsGetRdb(ts), tag);
@@ -950,19 +943,29 @@ static void addIndexToDepHashes(rpmts ts, rpmDbiTag tag,
key++;
keylen--;
if (*key == '/' && filenothash)
- addFileDepToHash(filenothash, key, keylen);
+ addFileDepToHash(pool, filenothash, key, keylen);
if (depnothash)
- addDepToHash(depnothash, key, keylen);
+ addDepToHash(pool, depnothash, key, keylen);
} else {
if (*key == '/' && filehash)
- addFileDepToHash(filehash, key, keylen);
+ addFileDepToHash(pool, filehash, key, keylen);
if (dephash)
- addDepToHash(dephash, key, keylen);
+ addDepToHash(pool, dephash, key, keylen);
}
}
rpmdbIndexIteratorFree(ii);
}
+static unsigned int sidHash(rpmsid sid)
+{
+ return sid;
+}
+
+static int sidCmp(rpmsid a, rpmsid b)
+{
+ return (a != b);
+}
+
int rpmtsCheck(rpmts ts)
{
@@ -999,14 +1002,9 @@ int rpmtsCheck(rpmts ts)
(depCacheFreeKey)rfree, NULL);
/* build hashes of all confilict sdependencies */
- confilehash = filedepHashCreate(257, rstrhash, strcmp,
- (filedepHashFreeKey)rfree,
- (filedepHashFreeData)rfree);
- connothash = depexistsHashCreate(257, rstrhash, strcmp,
- (filedepHashFreeKey)rfree);
- connotfilehash = filedepHashCreate(257, rstrhash, strcmp,
- (filedepHashFreeKey)rfree,
- (filedepHashFreeData)rfree);
+ confilehash = filedepHashCreate(257, sidHash, sidCmp, NULL, NULL);
+ connothash = depexistsHashCreate(257, sidHash, sidCmp, NULL);
+ connotfilehash = filedepHashCreate(257, sidHash, sidCmp, NULL, NULL);
addIndexToDepHashes(ts, RPMTAG_CONFLICTNAME, NULL, confilehash, connothash, connotfilehash);
if (!filedepHashNumKeys(confilehash))
confilehash = filedepHashFree(confilehash);
@@ -1016,14 +1014,9 @@ int rpmtsCheck(rpmts ts)
connotfilehash = filedepHashFree(connotfilehash);
/* build hashes of all requires dependencies */
- reqfilehash = filedepHashCreate(8191, rstrhash, strcmp,
- (filedepHashFreeKey)rfree,
- (filedepHashFreeData)rfree);
- reqnothash = depexistsHashCreate(257, rstrhash, strcmp,
- (filedepHashFreeKey)rfree);
- reqnotfilehash = filedepHashCreate(257, rstrhash, strcmp,
- (filedepHashFreeKey)rfree,
- (filedepHashFreeData)rfree);
+ reqfilehash = filedepHashCreate(8191, sidHash, sidCmp, NULL, NULL);
+ reqnothash = depexistsHashCreate(257, sidHash, sidCmp, NULL);
+ reqnotfilehash = filedepHashCreate(257, sidHash, sidCmp, NULL, NULL);
addIndexToDepHashes(ts, RPMTAG_REQUIRENAME, NULL, reqfilehash, reqnothash, reqnotfilehash);
if (!filedepHashNumKeys(reqfilehash))
reqfilehash = filedepHashFree(reqfilehash);
@@ -1053,7 +1046,7 @@ int rpmtsCheck(rpmts ts)
/* Check provides against conflicts in installed packages. */
while (rpmdsNext(provides) >= 0) {
checkInstDeps(ts, dcache, p, RPMTAG_CONFLICTNAME, NULL, provides, 0);
- if (reqnothash && depexistsHashHasEntry(reqnothash, rpmdsN(provides)))
+ if (reqnothash && depexistsHashHasEntry(reqnothash, rpmdsNId(provides)))
checkInstDeps(ts, dcache, p, RPMTAG_REQUIRENAME, NULL, provides, 1);
}
@@ -1093,13 +1086,13 @@ int rpmtsCheck(rpmts ts)
/* Check provides and filenames against installed dependencies. */
while (rpmdsNext(provides) >= 0) {
checkInstDeps(ts, dcache, p, RPMTAG_REQUIRENAME, NULL, provides, 0);
- if (connothash && depexistsHashHasEntry(connothash, rpmdsN(provides)))
+ if (connothash && depexistsHashHasEntry(connothash, rpmdsNId(provides)))
checkInstDeps(ts, dcache, p, RPMTAG_CONFLICTNAME, NULL, provides, 1);
}
if (reqfilehash || connotfilehash) {
rpmfiles files = rpmteFiles(p);
- rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD);;
+ rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD);
while (rpmfiNext(fi) >= 0) {
if (RPMFILE_IS_INSTALLED(rpmfiFState(fi))) {
if (reqfilehash)