Skip to content
Snippets Groups Projects
Commit 2dc95279 authored by deuce's avatar deuce
Browse files

Optimization for fexist() and fexistcase() when neither * nor ? is present

on the passed path...
For fexist() simply return TRUE if access()!=-1 && !isdir()
For fexistcase() *try* the access()/isdir() method first, then do the full
search.  Should make a reasonable difference.  Profileing suggests that
iniFileName() is quite slow due to the fexistcase() calls.  As the general
case is that the passed path is correct, this should speed up most calls
to fexist*().
parent 22ff08c1
No related branches found
No related tags found
No related merge requests found
...@@ -418,6 +418,21 @@ long DLLCALL flength(const char *filename) ...@@ -418,6 +418,21 @@ long DLLCALL flength(const char *filename)
#endif #endif
} }
/****************************************************************************/
/* Checks the file system for the existence of one or more files. */
/* Returns TRUE if it exists, FALSE if it doesn't. */
/* 'filespec' may *NOT* contain wildcards! */
/****************************************************************************/
static BOOL fnameexist(const char *filename)
{
if(access(filename,0)==-1)
return(FALSE);
if(!isdir(filename))
return(TRUE);
return(FALSE);
}
/****************************************************************************/ /****************************************************************************/
/* Checks the file system for the existence of one or more files. */ /* Checks the file system for the existence of one or more files. */
/* Returns TRUE if it exists, FALSE if it doesn't. */ /* Returns TRUE if it exists, FALSE if it doesn't. */
...@@ -430,8 +445,8 @@ BOOL DLLCALL fexist(const char *filespec) ...@@ -430,8 +445,8 @@ BOOL DLLCALL fexist(const char *filespec)
long handle; long handle;
struct _finddata_t f; struct _finddata_t f;
if(access(filespec,0)==-1 && !strchr(filespec,'*') && !strchr(filespec,'?')) if(!strchr(filespec,'*') && !strchr(filespec,'?'))
return(FALSE); return(fnameexist(filespec));
if((handle=_findfirst((char*)filespec,&f))==-1) if((handle=_findfirst((char*)filespec,&f))==-1)
return(FALSE); return(FALSE);
...@@ -450,8 +465,8 @@ BOOL DLLCALL fexist(const char *filespec) ...@@ -450,8 +465,8 @@ BOOL DLLCALL fexist(const char *filespec)
glob_t g; glob_t g;
int c; int c;
if(access(filespec,0)==-1 && !strchr(filespec,'*') && !strchr(filespec,'?')) if(!strchr(filespec,'*') && !strchr(filespec,'?'))
return(FALSE); return(fnameexist(filespec));
/* start the search */ /* start the search */
glob(filespec, GLOB_MARK | GLOB_NOSORT, NULL, &g); glob(filespec, GLOB_MARK | GLOB_NOSORT, NULL, &g);
...@@ -488,8 +503,8 @@ BOOL DLLCALL fexistcase(char *path) ...@@ -488,8 +503,8 @@ BOOL DLLCALL fexistcase(char *path)
long handle; long handle;
struct _finddata_t f; struct _finddata_t f;
if(access(path,0)==-1 && !strchr(path,'*') && !strchr(path,'?')) if(!strchr(path,'*') && !strchr(path,'?'))
return(FALSE); return(fnameexist(path));
if((handle=_findfirst((char*)path,&f))==-1) if((handle=_findfirst((char*)path,&f))==-1)
return(FALSE); return(FALSE);
...@@ -513,6 +528,9 @@ BOOL DLLCALL fexistcase(char *path) ...@@ -513,6 +528,9 @@ BOOL DLLCALL fexistcase(char *path)
int i; int i;
glob_t glb; glob_t glb;
if(!strchr(path,'*') && !strchr(path,'?') && fnameexist(path))
return(TRUE);
SAFECOPY(globme,path); SAFECOPY(globme,path);
p=getfname(globme); p=getfname(globme);
SAFECOPY(fname,p); SAFECOPY(fname,p);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment