Ignore:
Timestamp:
Sep 20, 2016, 5:36:07 PM (9 years ago)
Author:
bird
Message:

kWorker/kDep: save a few header stat calls while optimizing dependencies.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kWorker/kWorker.c

    r2946 r2948  
    4747#include "nt/ntstat.h"
    4848#include "kbuild_version.h"
    49 /* lib/nt_fullpath.c */
    50 extern void nt_fullpath(const char *pszPath, char *pszFull, size_t cchFull);
    5149
    5250#include "nt/ntstuff.h"
     
    5452
    5553#include "nt/kFsCache.h"
     54#include "nt_fullpath.h"
    5655#include "quote_argv.h"
    5756#include "md5.h"
     
    28002799 */
    28012800
     2801
     2802/**
     2803 * This is for kDep.
     2804 */
     2805int kwFsPathExists(const char *pszPath)
     2806{
     2807    BirdTimeSpec_T  TsIgnored;
     2808    KFSLOOKUPERROR  enmError;
     2809    PKFSOBJ         pFsObj = kFsCacheLookupNoMissingA(g_pFsCache, pszPath, &enmError);
     2810    if (pFsObj)
     2811    {
     2812        kFsCacheObjRelease(g_pFsCache, pFsObj);
     2813        return 1;
     2814    }
     2815    return birdStatModTimeOnly(pszPath, &TsIgnored, 1) == 0;
     2816}
     2817
     2818
     2819/* duplicated in dir-nt-bird.c */
     2820void nt_fullpath_cached(const char *pszPath, char *pszFull, size_t cbFull)
     2821{
     2822    KFSLOOKUPERROR  enmError;
     2823    PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
     2824    if (pPathObj)
     2825    {
     2826        KSIZE off = pPathObj->cchParent;
     2827        if (off > 0)
     2828        {
     2829            KSIZE offEnd = off + pPathObj->cchName;
     2830            if (offEnd < cbFull)
     2831            {
     2832                PKFSDIR pAncestor;
     2833
     2834                pszFull[off + pPathObj->cchName] = '\0';
     2835                memcpy(&pszFull[off], pPathObj->pszName, pPathObj->cchName);
     2836
     2837                for (pAncestor = pPathObj->pParent; off > 0; pAncestor = pAncestor->Obj.pParent)
     2838                {
     2839                    kHlpAssert(off > 1);
     2840                    kHlpAssert(pAncestor != NULL);
     2841                    kHlpAssert(pAncestor->Obj.cchName > 0);
     2842                    pszFull[--off] = '/';
     2843                    off -= pAncestor->Obj.cchName;
     2844                    kHlpAssert(pAncestor->Obj.cchParent == off);
     2845                    memcpy(&pszFull[off], pAncestor->Obj.pszName, pAncestor->Obj.cchName);
     2846                }
     2847                kFsCacheObjRelease(g_pFsCache, pPathObj);
     2848                return;
     2849            }
     2850        }
     2851        else
     2852        {
     2853            if ((size_t)pPathObj->cchName + 1 < cbFull)
     2854            {
     2855                memcpy(pszFull, pPathObj->pszName, pPathObj->cchName);
     2856                pszFull[pPathObj->cchName] = '/';
     2857                pszFull[pPathObj->cchName + 1] = '\0';
     2858
     2859                kFsCacheObjRelease(g_pFsCache, pPathObj);
     2860                return;
     2861            }
     2862        }
     2863
     2864        /* do fallback. */
     2865        kHlpAssertFailed();
     2866        kFsCacheObjRelease(g_pFsCache, pPathObj);
     2867    }
     2868
     2869    nt_fullpath(pszPath, pszFull, cbFull);
     2870}
    28022871
    28032872
Note: See TracChangeset for help on using the changeset viewer.