From 5f9af37583f910ed1adaea770687d4c99caa0a24 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 28 Sep 2012 12:43:39 +0300 Subject: [PATCH] Simplify fpLookupSubdir() a bit - Use string offsets for basename start and end to track the progress, avoiding +1/-1 adjustments in every damn calculation. - Reduce the places where new basename is calculated to just one at the start of the main loop, just adjust the basename start and end accordingly beforehand. - This shouldn't change any functionality, just simplify the code a little bit. --- lib/fprint.c | 55 ++++++++++++++++++++++--------------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/lib/fprint.c b/lib/fprint.c index e50b1cd..6f6172c 100644 --- a/lib/fprint.c +++ b/lib/fprint.c @@ -337,8 +337,8 @@ static void fpLookupSubdir(rpmFpHash symlinks, fingerPrintCache fpc, rpmte p, in { rpmfi fi = rpmteFI(p); struct fingerPrint_s current_fp; - const char *endsubdir, *endbasename, *currentsubdir; - size_t lensubDir; + const char *currentsubdir; + size_t lensubDir, bnStart, bnEnd; struct rpmffi_s * recs; int numRecs; @@ -357,21 +357,20 @@ static void fpLookupSubdir(rpmFpHash symlinks, fingerPrintCache fpc, rpmte p, in current_fp = *fp; /* Set baseName to the upper most dir */ - endbasename = currentsubdir + 1; - while (*endbasename != '/' && endbasename < currentsubdir + lensubDir) - endbasename++; - current_fp.baseNameId = rpmstrPoolIdn(fpc->pool, currentsubdir + 1, - endbasename - currentsubdir - 1, 1); + bnStart = bnEnd = 1; + while (bnEnd < lensubDir && currentsubdir[bnEnd] != '/') + bnEnd++; /* no subDir for now */ current_fp.subDirId = 0; - endsubdir = NULL; - while (endbasename < currentsubdir + lensubDir) { - char found; - found = 0; + while (bnEnd < lensubDir) { + char found = 0; - rpmFpHashGetEntry(symlinks, ¤t_fp, - &recs, &numRecs, NULL); + current_fp.baseNameId = rpmstrPoolIdn(fpc->pool, + currentsubdir + bnStart, + bnEnd - bnStart, 1); + + rpmFpHashGetEntry(symlinks, ¤t_fp, &recs, &numRecs, NULL); for (i=0; ipool, fp->baseNameId); @@ -416,17 +415,11 @@ static void fpLookupSubdir(rpmFpHash symlinks, fingerPrintCache fpc, rpmte p, in lensubDir = rpmstrPoolStrlen(fpc->pool, fp->subDirId); /* no subDir for now */ current_fp.subDirId = 0; - endsubdir = NULL; /* Set baseName to the upper most dir */ - endbasename = currentsubdir + 1; - while (*endbasename != '/' && - endbasename < currentsubdir + lensubDir) - endbasename++; - current_fp.baseNameId = rpmstrPoolIdn(fpc->pool, - currentsubdir + 1, - endbasename - currentsubdir - 1, - 1); + bnStart = bnEnd = 1; + while (bnEnd < lensubDir && currentsubdir[bnEnd] != '/') + bnEnd++; break; } @@ -443,17 +436,13 @@ static void fpLookupSubdir(rpmFpHash symlinks, fingerPrintCache fpc, rpmte p, in } /* Set former baseName as subDir */ - current_fp.subDirId = rpmstrPoolIdn(fpc->pool, currentsubdir, - endbasename - currentsubdir + 1, 1); - endsubdir = endbasename; + bnEnd++; + current_fp.subDirId = rpmstrPoolIdn(fpc->pool, currentsubdir, bnEnd, 1); /* set baseName to the next lower dir */ - endbasename++; - while (*endbasename != '\0' && *endbasename != '/') - endbasename++; - current_fp.baseNameId = rpmstrPoolIdn(fpc->pool, endsubdir + 1, - endbasename - endsubdir - 1, 1); - + bnStart = bnEnd; + while (bnEnd < lensubDir && currentsubdir[bnEnd] != '/') + bnEnd++; } rpmFpHashAddEntry(fpc->fp, fp, ffi); -- 2.7.4