version 1.50, 2007/09/16 12:19:15 |
version 1.51, 2007/09/16 12:30:35 |
|
|
* hampers the style of some makefiles, they must be changed. |
* hampers the style of some makefiles, they must be changed. |
* |
* |
* A list of all previously-read directories is kept in the |
* A list of all previously-read directories is kept in the |
* openDirectories cache. |
* knownDirectories cache. |
* |
* |
* The need for the caching of whole directories is brought about by |
* The need for the caching of whole directories is brought about by |
* the multi-level transformation code in suff.c, which tends to search |
* the multi-level transformation code in suff.c, which tends to search |
|
|
* sense to replace the access() with a stat() and record the mtime |
* sense to replace the access() with a stat() and record the mtime |
* in a cache for when Dir_MTime was actually called. */ |
* in a cache for when Dir_MTime was actually called. */ |
|
|
static LIST thedirSearchPath; /* main search path */ |
static LIST theDefaultPath; /* main search path */ |
Lst dirSearchPath= &thedirSearchPath; |
Lst defaultPath= &theDefaultPath; |
|
|
#ifdef DEBUG_DIRECTORY_CACHE |
#ifdef DEBUG_DIRECTORY_CACHE |
/* Variables for gathering statistics on the efficiency of the hashing |
/* Variables for gathering statistics on the efficiency of the hashing |
|
|
char name[1]; /* ...for that file. */ |
char name[1]; /* ...for that file. */ |
}; |
}; |
|
|
static struct ohash openDirectories; /* cache all open directories */ |
static struct ohash knownDirectories; /* cache all open directories */ |
|
|
/* Global structure used to cache mtimes. XXX We don't cache an mtime |
/* Global structure used to cache mtimes. XXX We don't cache an mtime |
* before a caller actually looks up for the given time, because of the |
* before a caller actually looks up for the given time, because of the |
|
|
/* There are three distinct hash structures: |
/* There are three distinct hash structures: |
* - to collate files's last modification times (global mtimes) |
* - to collate files's last modification times (global mtimes) |
* - to collate file names (in each PathEntry structure) |
* - to collate file names (in each PathEntry structure) |
* - to collate known directories (global openDirectories). */ |
* - to collate known directories (global knownDirectories). */ |
static struct ohash_info stamp_info = { |
static struct ohash_info stamp_info = { |
offsetof(struct file_stamp, name), NULL, hash_alloc, hash_free, |
offsetof(struct file_stamp, name), NULL, hash_alloc, hash_free, |
element_alloc }; |
element_alloc }; |
|
|
{ |
{ |
char *dotname = "."; |
char *dotname = "."; |
|
|
Static_Lst_Init(dirSearchPath); |
Static_Lst_Init(defaultPath); |
ohash_init(&openDirectories, 4, &dir_info); |
ohash_init(&knownDirectories, 4, &dir_info); |
ohash_init(&mtimes, 4, &stamp_info); |
ohash_init(&mtimes, 4, &stamp_info); |
|
|
|
|
|
|
|
|
dot->refCount--; |
dot->refCount--; |
Dir_Destroy(dot); |
Dir_Destroy(dot); |
Lst_Destroy(dirSearchPath, Dir_Destroy); |
Lst_Destroy(defaultPath, Dir_Destroy); |
for (p = ohash_first(&openDirectories, &i); p != NULL; |
for (p = ohash_first(&knownDirectories, &i); p != NULL; |
p = ohash_next(&openDirectories, &i)) |
p = ohash_next(&knownDirectories, &i)) |
Dir_Destroy(p); |
Dir_Destroy(p); |
ohash_delete(&openDirectories); |
ohash_delete(&knownDirectories); |
free_hash(&mtimes); |
free_hash(&mtimes); |
} |
} |
#endif |
#endif |
|
|
struct dirent *dp; |
struct dirent *dp; |
unsigned int slot; |
unsigned int slot; |
|
|
slot = ohash_qlookupi(&openDirectories, name, &ename); |
slot = ohash_qlookupi(&knownDirectories, name, &ename); |
p = ohash_find(&openDirectories, slot); |
p = ohash_find(&knownDirectories, slot); |
|
|
if (p != NULL) |
if (p != NULL) |
return p; |
return p; |
|
|
if (DEBUG(DIR)) |
if (DEBUG(DIR)) |
printf("done\n"); |
printf("done\n"); |
|
|
ohash_insert(&openDirectories, slot, p); |
ohash_insert(&knownDirectories, slot, p); |
return p; |
return p; |
} |
} |
|
|
|
|
struct PathEntry *p = (struct PathEntry *)pp; |
struct PathEntry *p = (struct PathEntry *)pp; |
|
|
if (--p->refCount == 0) { |
if (--p->refCount == 0) { |
ohash_remove(&openDirectories, |
ohash_remove(&knownDirectories, |
ohash_qlookup(&openDirectories, p->name)); |
ohash_qlookup(&knownDirectories, p->name)); |
free_hash(&p->files); |
free_hash(&p->files); |
free(p); |
free(p); |
} |
} |
|
|
(hits+bigmisses+nearmisses ? |
(hits+bigmisses+nearmisses ? |
hits * 100 / (hits + bigmisses + nearmisses) : 0)); |
hits * 100 / (hits + bigmisses + nearmisses) : 0)); |
printf("# %-20s referenced\thits\n", "directory"); |
printf("# %-20s referenced\thits\n", "directory"); |
for (p = ohash_first(&openDirectories, &i); p != NULL; |
for (p = ohash_first(&knownDirectories, &i); p != NULL; |
p = ohash_next(&openDirectories, &i)) |
p = ohash_next(&knownDirectories, &i)) |
printf("# %-20s %10d\t%4d\n", p->name, p->refCount, p->hits); |
printf("# %-20s %10d\t%4d\n", p->name, p->refCount, p->hits); |
} |
} |
#endif |
#endif |
|
|
return Arch_MTime(gn); |
return Arch_MTime(gn); |
|
|
if (gn->path == NULL) { |
if (gn->path == NULL) { |
fullName = Dir_FindFile(gn->name, dirSearchPath); |
fullName = Dir_FindFile(gn->name, defaultPath); |
if (fullName == NULL) |
if (fullName == NULL) |
fullName = estrdup(gn->name); |
fullName = estrdup(gn->name); |
} else |
} else |