From 2dc9527902fd8dd00a696fafa523a55a38b29664 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Fri, 7 Apr 2006 18:52:56 +0000
Subject: [PATCH] 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*().

---
 src/xpdev/dirwrap.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c
index c6dddfd051..1ae797cab1 100644
--- a/src/xpdev/dirwrap.c
+++ b/src/xpdev/dirwrap.c
@@ -418,6 +418,21 @@ long DLLCALL flength(const char *filename)
 #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.			*/
 /* Returns TRUE if it exists, FALSE if it doesn't.                          */
@@ -430,8 +445,8 @@ BOOL DLLCALL fexist(const char *filespec)
 	long	handle;
 	struct _finddata_t f;
 
-	if(access(filespec,0)==-1 && !strchr(filespec,'*') && !strchr(filespec,'?'))
-		return(FALSE);
+	if(!strchr(filespec,'*') && !strchr(filespec,'?'))
+		return(fnameexist(filespec));
 
 	if((handle=_findfirst((char*)filespec,&f))==-1)
 		return(FALSE);
@@ -450,8 +465,8 @@ BOOL DLLCALL fexist(const char *filespec)
 	glob_t g;
     int c;
 
-	if(access(filespec,0)==-1 && !strchr(filespec,'*') && !strchr(filespec,'?'))
-		return(FALSE);
+	if(!strchr(filespec,'*') && !strchr(filespec,'?'))
+		return(fnameexist(filespec));
 
     /* start the search */
     glob(filespec, GLOB_MARK | GLOB_NOSORT, NULL, &g);
@@ -488,8 +503,8 @@ BOOL DLLCALL fexistcase(char *path)
 	long	handle;
 	struct _finddata_t f;
 
-	if(access(path,0)==-1 && !strchr(path,'*') && !strchr(path,'?'))
-		return(FALSE);
+	if(!strchr(path,'*') && !strchr(path,'?'))
+		return(fnameexist(path));
 
 	if((handle=_findfirst((char*)path,&f))==-1)
 		return(FALSE);
@@ -513,6 +528,9 @@ BOOL DLLCALL fexistcase(char *path)
 	int  i;
 	glob_t	glb;
 	
+	if(!strchr(path,'*') && !strchr(path,'?') && fnameexist(path))
+		return(TRUE);
+
 	SAFECOPY(globme,path);
 	p=getfname(globme);
 	SAFECOPY(fname,p);
-- 
GitLab