From: Panu Matilainen Date: Fri, 28 Sep 2012 09:43:39 +0000 (+0300) Subject: Simplify fpLookupSubdir() a bit X-Git-Tag: tznext/4.11.0.1.tizen20130304~203 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5f9af37583f910ed1adaea770687d4c99caa0a24;p=tools%2Flibrpm-tizen.git 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. --- 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);