Changeset 3132 for trunk/tools


Ignore:
Timestamp:
Mar 17, 2000, 12:51:26 AM (26 years ago)
Author:
bird
Message:

More performance improovements:

  • Cache entire directories. When the number of scanned files are > 25 in one file specification.
  • Lowercases all names added to the trees and uses case sentivie key searches.
  • Added a tree of cached directories so that these are not searched with the slow DosQueryPathInfo too.
Location:
trunk/tools/fastdep
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/fastdep/avl.h

    r3129 r3132  
    1 /* $Id: avl.h,v 1.1 2000-03-16 21:10:10 bird Exp $
     1/* $Id: avl.h,v 1.2 2000-03-16 23:51:25 bird Exp $
    22 *
    33 * AVL-Tree (lookalike) declaration.
     
    88 * one type of trees within one program (module).
    99 *
    10  * TREETYPE: Case Insensitive Strings (Key is pointer).
     10 * TREETYPE: Case Sensitive Strings (Key is pointer).
    1111 *
    1212 *
     
    3232 * AVL Compare macros
    3333 */
    34 #define AVL_L(key1, key2)  (stricmp(key1, key2) <  0)
    35 #define AVL_LE(key1, key2) (stricmp(key1, key2) <= 0)
    36 #define AVL_G(key1, key2)  (stricmp(key1, key2) >  0)
    37 #define AVL_GE(key1, key2) (stricmp(key1, key2) >= 0)
    38 #define AVL_E(key1, key2)  (stricmp(key1, key2) == 0)
    39 #define AVL_NE(key1, key2) (stricmp(key1, key2) != 0)
     34#define AVL_L(key1, key2)  (strcmp(key1, key2) <  0)
     35#define AVL_LE(key1, key2) (strcmp(key1, key2) <= 0)
     36#define AVL_G(key1, key2)  (strcmp(key1, key2) >  0)
     37#define AVL_GE(key1, key2) (strcmp(key1, key2) >= 0)
     38#define AVL_E(key1, key2)  (strcmp(key1, key2) == 0)
     39#define AVL_NE(key1, key2) (strcmp(key1, key2) != 0)
    4040
    4141
  • trunk/tools/fastdep/fastdep.c

    r3129 r3132  
    1 /* $Id: fastdep.c,v 1.9 2000-03-16 21:10:11 bird Exp $
     1/* $Id: fastdep.c,v 1.10 2000-03-16 23:51:26 bird Exp $
    22 *
    33 * Fast dependents. (Fast = Quick and Dirty!)
     
    152152
    153153/* file operations */
    154 char *filePath(const char *pszFilename, char *pszBuffer);
    155 char *filePathSlash(const char *pszFilename, char *pszBuffer);
    156 char *fileName(const char *pszFilename, char *pszBuffer);
    157 char *fileNameNoExt(const char *pszFilename, char *pszBuffer);
    158 char *fileExt(const char *pszFilename, char *pszBuffer);
     154static char *fileNormalize(char *pszFilename);
     155       char *filePath(const char *pszFilename, char *pszBuffer);
     156static char *filePathSlash(const char *pszFilename, char *pszBuffer);
     157static char *filePathSlash2(const char *pszFilename, char *pszBuffer);
     158static char *fileName(const char *pszFilename, char *pszBuffer);
     159static char *fileNameNoExt(const char *pszFilename, char *pszBuffer);
     160static char *fileExt(const char *pszFilename, char *pszBuffer);
    159161
    160162/* filecache operations */
    161 static BOOL filecacheAdd(const char *pszFilename);
     163static BOOL filecacheAddFile(const char *pszFilename);
     164static BOOL filecacheAddDir(const char *pszDir);
    162165static BOOL filecacheFind(const char *pszFilename);
     166static BOOL filecacheIsDirCached(const char *pszDir);
    163167
    164168/* pathlist operations */
     
    202206 */
    203207static PDEPRULE pdepList = NULL;
     208static BOOL     fCacheSearchDirs = FALSE;
     209
    204210
    205211/*
     
    208214static PFCACHEENTRY pfcTree = NULL;
    209215static unsigned     cfcNodes = 0;
     216static PFCACHEENTRY pfcDirTree = NULL;
    210217
    211218
     
    452459        else
    453460        {   /* not a parameter! */
    454             ULONG        ulRc;
    455             FILEFINDBUF3 filebuf;
    456             HDIR         hDir = HDIR_CREATE;
    457             ULONG        ulFound = 1;
    458 
    459             memset(&filebuf, 0, sizeof(filebuf));
     461            ULONG           ulRc;
     462            char            achBuffer[4096];
     463            PFILEFINDBUF3   pfindbuf3 = (PFILEFINDBUF3)(void*)&achBuffer[0];
     464            HDIR            hDir = HDIR_CREATE;
     465            ULONG           cFiles = ~0UL;
     466            int             i;
    460467
    461468            /*
     
    471478            ulRc = DosFindFirst(argv[argi], &hDir,
    472479                                FILE_READONLY |  FILE_HIDDEN | FILE_SYSTEM | FILE_ARCHIVED,
    473                                 &filebuf, sizeof(FILEFINDBUF3), &ulFound, FIL_STANDARD);
     480                                pfindbuf3, sizeof(achBuffer), &cFiles, FIL_STANDARD);
     481            if (!fCacheSearchDirs)
     482                fCacheSearchDirs = cFiles > 25;
    474483            while (ulRc == NO_ERROR)
    475484            {
    476                 char *psz;
    477                 char  szSource[CCHMAXPATH];
    478 
    479                 /*
    480                  * Make full path.
    481                  */
    482                 if ((psz = strrchr(argv[argi], '\\')) || (psz = strrchr(argv[argi], '/')))
     485                for (i = 0;
     486                     i < cFiles;
     487                     i++, pfindbuf3 = (PFILEFINDBUF3)((int)pfindbuf3 + pfindbuf3->oNextEntryOffset)
     488                     )
    483489                {
    484                     strncpy(szSource, argv[argi], psz - argv[argi] + 1);
    485                     szSource[psz - argv[argi] + 1]  = '\0';
     490                    char *psz;
     491                    char  szSource[CCHMAXPATH];
     492
     493                    /*
     494                     * Make full path.
     495                     */
     496                    if ((psz = strrchr(argv[argi], '\\')) || (psz = strrchr(argv[argi], '/')))
     497                    {
     498                        strncpy(szSource, argv[argi], psz - argv[argi] + 1);
     499                        szSource[psz - argv[argi] + 1]  = '\0';
     500                    }
     501                    else
     502                        szSource[0]  = '\0';
     503                    strcat(szSource, pfindbuf3->achName);
     504
     505                    /*
     506                     * Analyse the file.
     507                     */
     508                    rc -= makeDependent(&szSource[0], &options);
    486509                }
    487                 else
    488                     szSource[0]  = '\0';
    489                 strcat(szSource, filebuf.achName);
    490 
    491                 /*
    492                  * Analyse the file.
    493                  */
    494                 rc -= makeDependent(&szSource[0], &options);
    495510
    496511                /* next file */
    497                 ulRc = DosFindNext(hDir, &filebuf, sizeof(filebuf), &ulFound);
     512                cFiles = ~0UL;
     513                pfindbuf3 = (PFILEFINDBUF3)(void*)&achBuffer[0];
     514                ulRc = DosFindNext(hDir, pfindbuf3, sizeof(achBuffer), &cFiles);
    498515            }
    499516            DosFindClose(hDir);
     
    13031320}
    13041321
     1322
     1323/**
     1324 * Normalizes the path slashes for the filename.
     1325 * @returns   pszFilename
     1326 * @param     pszFilename  Pointer to filename string.
     1327 */
     1328char *fileNormalize(char *pszFilename)
     1329{
     1330    char *psz = pszFilename;
     1331
     1332    while ((pszFilename = strchr(pszFilename, '//')) != NULL)
     1333        *pszFilename++ = '\\';
     1334
     1335    return psz;
     1336}
     1337
    13051338/**
    13061339 * Copies the path part (excluding the slash) into pszBuffer and returns
     
    13411374 * @author    knut st. osmundsen
    13421375 */
    1343 char *filePathSlash(const char *pszFilename, char *pszBuffer)
     1376static char *filePathSlash(const char *pszFilename, char *pszBuffer)
    13441377{
    13451378    char *psz = strrchr(pszFilename, '\\');
     
    13531386        strncpy(pszBuffer, pszFilename, psz - pszFilename + 1);
    13541387        pszBuffer[psz - pszFilename + 1] = '\0';
     1388    }
     1389
     1390    return pszBuffer;
     1391}
     1392
     1393
     1394/**
     1395 * Copies the path part including the slash into pszBuffer and returns
     1396 * a pointer to the buffer. If no path is found "" is returned.
     1397 * The path is normalized to only use '\\'.
     1398 * @returns   Pointer to pszBuffer with path.
     1399 * @param     pszFilename  Pointer to readonly filename.
     1400 * @param     pszBuffer    Pointer to output Buffer.
     1401 * @status    completely implemented.
     1402 * @author    knut st. osmundsen
     1403 */
     1404static char *filePathSlash2(const char *pszFilename, char *pszBuffer)
     1405{
     1406    char *psz = strrchr(pszFilename, '\\');
     1407    if (psz == NULL)
     1408        psz = strrchr(pszFilename, '/');
     1409
     1410    if (psz == NULL)
     1411        *pszBuffer = '\0';
     1412    else
     1413    {
     1414        strncpy(pszBuffer, pszFilename, psz - pszFilename + 1);
     1415        pszBuffer[psz - pszFilename + 1] = '\0';
     1416
     1417        /* normalize all '/' to '\\' */
     1418        psz = pszBuffer;
     1419        while ((psz = strchr(psz, '/')) != NULL)
     1420               *psz++ = '\\';
    13551421    }
    13561422
     
    14391505 * @param     pszFilename   Name of the file which is to be added. (with path!)
    14401506 */
    1441 static BOOL filecacheAdd(const char *pszFilename)
     1507static BOOL filecacheAddFile(const char *pszFilename)
    14421508{
    14431509    PFCACHEENTRY pfcNew;
     
    14571523        return TRUE;
    14581524    }
    1459 
    14601525    cfcNodes++;
    14611526
     
    14661531
    14671532/**
    1468  * Checks if pszFile is exists in the cache.
     1533 * Adds a file to the cache.
     1534 * @returns   Success indicator.
     1535 * @param     pszDir   Name of the path which is to be added. (with slash!)
     1536 */
     1537static BOOL filecacheAddDir(const char *pszDir)
     1538{
     1539    PFCACHEENTRY    pfcNew;
     1540    APIRET          rc;
     1541    char            szDir[CCHMAXPATH];
     1542    int             cchDir;
     1543    char            achBuffer[16384];
     1544    PFILEFINDBUF3   pfindbuf3 = (PFILEFINDBUF3)(void*)&achBuffer[0];
     1545    HDIR            hDir = HDIR_CREATE;
     1546    ULONG           cFiles = 0xFFFFFFF;
     1547    int             i;
     1548
     1549    /* Make path */
     1550    filePathSlash2(pszDir, szDir);
     1551    strlwr(szDir); /* Convert name to lower case to allow faster searchs! */
     1552    cchDir = strlen(szDir);
     1553
     1554
     1555    /* Add directory to pfcDirTree. */
     1556    pfcNew = malloc(sizeof(FCACHEENTRY) + cchDir + 1);
     1557    if (pfcNew == NULL)
     1558    {
     1559        fprintf(stderr, "error: out of memory! (line=%d)\n", __LINE__);
     1560        DosFindClose(hDir);
     1561        return FALSE;
     1562    }
     1563    pfcNew->Key = (char*)(void*)pfcNew + sizeof(FCACHEENTRY);
     1564    strcpy((char*)(unsigned)pfcNew->Key, szDir);
     1565    AVLInsert(&pfcDirTree, pfcNew);
     1566
     1567
     1568    /* Start to search directory - all files */
     1569    strcat(szDir + cchDir, "*");
     1570    rc = DosFindFirst(szDir, &hDir, FILE_NORMAL,
     1571                      pfindbuf3, sizeof(achBuffer),
     1572                      &cFiles, FIL_STANDARD);
     1573    while (rc == NO_ERROR)
     1574    {
     1575        for (i = 0;
     1576             i < cFiles;
     1577             i++, pfindbuf3 = (PFILEFINDBUF3)((int)pfindbuf3 + pfindbuf3->oNextEntryOffset)
     1578             )
     1579        {
     1580            pfcNew = malloc(sizeof(FCACHEENTRY) + cchDir + pfindbuf3->cchName + 1);
     1581            if (pfcNew == NULL)
     1582            {
     1583                fprintf(stderr, "error: out of memory! (line=%d)\n", __LINE__);
     1584                DosFindClose(hDir);
     1585                return FALSE;
     1586            }
     1587            pfcNew->Key = (char*)(void*)pfcNew + sizeof(FCACHEENTRY);
     1588            strcpy((char*)(unsigned)pfcNew->Key, szDir);
     1589            strcpy((char*)(unsigned)pfcNew->Key + cchDir, pfindbuf3->achName);
     1590            strlwr((char*)(unsigned)pfcNew->Key + cchDir); /* Convert name to lower case to allow faster searchs! */
     1591            if (!AVLInsert(&pfcTree, pfcNew))
     1592                free(pfcNew);
     1593            else
     1594                cfcNodes++;
     1595            _heap_check();
     1596        }
     1597
     1598        /* next */
     1599        cFiles = 0xFFFFFFF;
     1600        pfindbuf3 = (PFILEFINDBUF3)(void*)&achBuffer[0];
     1601        rc = DosFindNext(hDir, pfindbuf3, sizeof(achBuffer), &cFiles);
     1602    }
     1603
     1604    DosFindClose(hDir);
     1605
     1606    return TRUE;
     1607}
     1608
     1609
     1610/**
     1611 * Checks if pszFilename is exists in the cache.
    14691612 * @return    TRUE if found. FALSE if not found.
    14701613 * @param     pszFilename   Name of the file to be found. (with path!)
     1614 *                          This is in lower case!
    14711615 */
    14721616static BOOL filecacheFind(const char *pszFilename)
    14731617{
    14741618    return AVLGet(&pfcTree, (AVLKEY)pszFilename) != NULL;
     1619}
     1620
     1621
     1622/**
     1623 * Checks if pszFilename is exists in the cache.
     1624 * @return    TRUE if found. FALSE if not found.
     1625 * @param     pszFilename   Name of the file to be found. (with path!)
     1626 *                          This is in lower case!
     1627 */
     1628static BOOL filecacheIsDirCached(const char *pszDir)
     1629{
     1630    return AVLGet(&pfcDirTree, (AVLKEY)pszDir) != NULL;
    14751631}
    14761632
     
    15171673                strcpy(&szFile[pszNext - psz], "\\");
    15181674            strcat(szFile, pszFilename);
     1675            strlwr(szFile); /* to speed up AVL tree search we'll lowercase all names. */
     1676            fileNormalize(szFile);
    15191677
    15201678            /*
     
    15241682            if (!filecacheFind(szFile))
    15251683            {
    1526                 FILESTATUS3 fsts3;
    1527 
    1528                 /* ask the OS */
    1529                 rc = DosQueryPathInfo(szFile, FIL_STANDARD, &fsts3, sizeof(fsts3));
    1530                 if (rc == NO_ERROR)
    1531                 {   /* add file to cache. */
    1532                     filecacheAdd(szFile);
     1684                char szDir[CCHMAXPATH];
     1685
     1686                filePathSlash(szFile, szDir);
     1687                if (filecacheIsDirCached(szDir))
     1688                    rc = ERROR_FILE_NOT_FOUND;
     1689                else
     1690                {
     1691                    /*
     1692                     * If caching of entire dirs are enabled, we'll
     1693                     * add the directory to the cache and search it.
     1694                     */
     1695                    if (fCacheSearchDirs && filecacheAddDir(szDir))
     1696                        rc = filecacheFind(szFile) ? NO_ERROR : ERROR_FILE_NOT_FOUND;
     1697                    else
     1698                    {
     1699                        FILESTATUS3 fsts3;
     1700
     1701                        /* ask the OS */
     1702                        rc = DosQueryPathInfo(szFile, FIL_STANDARD, &fsts3, sizeof(fsts3));
     1703                        if (rc == NO_ERROR)
     1704                        {   /* add file to cache. */
     1705                            filecacheAddFile(szFile);
     1706                        }
     1707                    }
    15331708                }
    15341709            }
  • trunk/tools/fastdep/makefile

    r3129 r3132  
    1 # $Id: makefile,v 1.4 2000-03-16 21:10:10 bird Exp $
     1# $Id: makefile,v 1.5 2000-03-16 23:51:26 bird Exp $
    22
    33#
     
    1717CFLAGS   = $(CFLAGS)  -Ge+ -Tx+ -I..\common \
    1818           -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -O+ -Tm-
    19 #          -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -Gh+
     19#          -W3 -Wall+ppt-ppc-inl-cnv-gnr-vft-gen-uni-ext- -Gh+ -Tm- #-O+
    2020LDFLAGS  = $(LDFLAGS) -Ge+ -Fe$@ /B"/MAP:full"
    2121!else
     
    3232fastdep.exe: fastdep.obj avl.obj
    3333    $(LD) $(LDFLAGS) $** $(RTLLIB) os2386.lib
    34 #   $(LD) $(LDFLAGS) $** CPPOPA3.OBJ $(RTLLIB) os2386.lib
     34#   $(LD) $(LDFLAGS) $** CPPOPA3.OBJ $(RTLLIB) _DOSCALL.LIB os2386.lib
    3535
    3636..\bin\fastdep.exe: fastdep.exe
Note: See TracChangeset for help on using the changeset viewer.