From 712101ba98c0e1c588652cef9b39ac5707c2f61c Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 5 Sep 2012 12:10:51 +0300 Subject: [PATCH] Prehash dir names on fingerprinting to avoid recalculating when adding - Speedup depends on transaction and yadda yadda, on my large erasure transaction testcase this is circa two percent saving on rstrhash() total costs. --- lib/fprint.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/fprint.c b/lib/fprint.c index 3aa9989..a579f6f 100644 --- a/lib/fprint.c +++ b/lib/fprint.c @@ -48,15 +48,16 @@ fingerPrintCache fpCacheFree(fingerPrintCache cache) * Find directory name entry in cache. * @param cache pointer to fingerprint cache * @param dirName string to locate in cache + * @param dirHash precalculated string hash * @return pointer to directory name entry (or NULL if not found). */ static const struct fprintCacheEntry_s * cacheContainsDirectory( fingerPrintCache cache, - const char * dirName) + const char * dirName, unsigned int dirHash) { const struct fprintCacheEntry_s ** data; - if (rpmFpEntryHashGetEntry(cache->ht, dirName, &data, NULL, NULL)) + if (rpmFpEntryHashGetHEntry(cache->ht, dirName, dirHash, &data, NULL, NULL)) return data[0]; return NULL; } @@ -131,11 +132,12 @@ fingerPrint fpLookup(fingerPrintCache cache, } while (1) { + /* buf contents change through end ptr, requiring rehash on each loop */ const char *fpDir = (*buf != '\0') ? buf : "/"; + unsigned int fpHash = rpmFpEntryHashKeyHash(cache->ht, fpDir); /* as we're stating paths here, we want to follow symlinks */ - - cacheHit = cacheContainsDirectory(cache, fpDir); + cacheHit = cacheContainsDirectory(cache, fpDir, fpHash); if (cacheHit != NULL) { fp.entry = cacheHit; } else if (!stat(fpDir, &sb)) { @@ -146,7 +148,8 @@ fingerPrint fpLookup(fingerPrintCache cache, newEntry->dirName = xstrdup(fpDir); fp.entry = newEntry; - rpmFpEntryHashAddEntry(cache->ht, newEntry->dirName, fp.entry); + rpmFpEntryHashAddHEntry(cache->ht, + newEntry->dirName, fpHash, fp.entry); } if (fp.entry) { -- 2.7.4