summaryrefslogtreecommitdiffstats
path: root/win/tclWinFile.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2000-10-21 00:43:01 (GMT)
committerhobbs <hobbs>2000-10-21 00:43:01 (GMT)
commit517724aedd37225321f8241834d1a907ec201bbd (patch)
treeea683d302f69affc88106dc87c7e881673c42728 /win/tclWinFile.c
parentacb5cca47a2f68aa628d4483e16f1dd4698462b5 (diff)
downloadtcl-517724aedd37225321f8241834d1a907ec201bbd.zip
tcl-517724aedd37225321f8241834d1a907ec201bbd.tar.gz
tcl-517724aedd37225321f8241834d1a907ec201bbd.tar.bz2
* win/tclWinFile.c (TclpMatchFilesTypes): made the stat call only
occur when necessary (for 'glob' command). Significantly speeds up glob command from 8.3. [BUG: 6216]
Diffstat (limited to 'win/tclWinFile.c')
-rw-r--r--win/tclWinFile.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index 1a689ac..d7c02c7 100644
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinFile.c,v 1.7 1999/12/12 22:46:51 hobbs Exp $
+ * RCS: @(#) $Id: tclWinFile.c,v 1.8 2000/10/21 00:43:02 hobbs Exp $
*/
#include "tclWinInt.h"
@@ -326,13 +326,20 @@ TclpMatchFilesTypes(
fname = Tcl_DStringValue(dirPtr);
nativeName = Tcl_WinUtfToTChar(fname, Tcl_DStringLength(dirPtr), &ds);
- attr = (*tclWinProcs->getFileAttributesProc)(nativeName);
- Tcl_DStringFree(&ds);
+
+ /*
+ * 'attr' represents the attributes of the file, but we only
+ * want to retrieve this info if it is absolutely necessary
+ * because it is an expensive call.
+ */
+
+ attr = NULL;
if (tail == NULL) {
int typeOk = 1;
if (types != NULL) {
if (types->perm != 0) {
+ attr = (*tclWinProcs->getFileAttributesProc)(nativeName);
if (
((types->perm & TCL_GLOB_PERM_RONLY) &&
!(attr & FILE_ATTRIBUTE_READONLY)) ||
@@ -389,13 +396,22 @@ TclpMatchFilesTypes(
Tcl_ListObjAppendElement(interp, resultPtr,
Tcl_NewStringObj(fname, Tcl_DStringLength(dirPtr)));
}
- } else if (attr & FILE_ATTRIBUTE_DIRECTORY) {
- Tcl_DStringAppend(dirPtr, "/", 1);
- result = TclDoGlob(interp, separators, dirPtr, tail, types);
- if (result != TCL_OK) {
- break;
+ } else {
+ attr = (*tclWinProcs->getFileAttributesProc)(nativeName);
+ if (attr & FILE_ATTRIBUTE_DIRECTORY) {
+ Tcl_DStringAppend(dirPtr, "/", 1);
+ result = TclDoGlob(interp, separators, dirPtr, tail, types);
+ if (result != TCL_OK) {
+ break;
+ }
}
}
+ /*
+ * Free ds here to ensure that nativeName is valid above.
+ */
+
+ Tcl_DStringFree(&ds);
+
Tcl_DStringSetLength(dirPtr, dirLength);
}