Artifacts Associated With Ticket 217914
Ticket change [f18cbb97b0] (rid 109379) by nobody on 2000-10-26 00:45:54:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
OriginalBugID: 2857 Bug Version: 8.2 SubmitDate: '1999-09-21' LastModified: '1999-09-24' Severity: MED Status: Closed Submitter: techsupp ChangedBy: hobbs RelatedBugIDs: 2867 OS: Windows NT Machine: X86 FixedDate: '2000-10-25' ClosedDate: '1999-09-24' Name: Matt Newman Extensions: so many..... CustomShell: This patch - I think all the others have been adopted. Comments: These patches only improve life on windows but the exact same approach should be used on the Mac too. the file * commands are used heavily and are far too costly for no good reason. This patch replaces the previous use of RegExp with a custom parser that is 20 times faster. This speeds up Tcl in all kinds of ways, esp. when handling the unknown proc. ReproducibleScript: puts [time {file split a:/b/c} 10000] 483 microseconds per interation puts [time {file join a:/b/c d/e} 10000] 507 microseconds per interation ObservedBehavior: 1/2 ms is a VERY long time to process 7 bytes of data! DesiredBehavior: It should take around 18 microseconds...... Patch: Index: tcl8.2/generic/tclFileName.c =================================================================== RCS file: /cvs/tcl/tcl8.2/generic/tclFileName.c,v retrieving revision 1.1.1.1 diff -w -b -c -r1.1.1.1 tclFileName.c *** tclFileName.c1999/08/19 12:32:001.1.1.1 --- tclFileName.c1999/09/21 19:54:35 *************** *** 18,31 **** #include "tclRegexp.h" /* - * The following regular expression matches the root portion of a Windows - * absolute or volume relative path. It will match both UNC and drive relative - * paths. - */ - - #define WIN_ROOT_PATTERN "^(([a-zA-Z]:)|[/\\\\][/\\\\]+([^/\\\\]+)[/\\\\]+([^/\\\\]+)|([/\\\\]))([/\\\\])*" - - /* * The following regular expression matches the root portion of a Macintosh * absolute path. It will match degenerate Unix-style paths, tilde paths, * Unix-style paths, and Mac paths. --- 18,23 ---- *************** *** 40,46 **** typedef struct ThreadSpecificData { int initialized; - Tcl_Obj *winRootPatternPtr; Tcl_Obj *macRootPatternPtr; } ThreadSpecificData; --- 32,37 ---- *************** *** 60,66 **** static char *DoTildeSubst _ANSI_ARGS_((Tcl_Interp *interp, CONST char *user, Tcl_DString *resultPtr)); static CONST char *ExtractWinRoot _ANSI_ARGS_((CONST char *path, ! Tcl_DString *resultPtr, int offset)); static voidFileNameCleanup _ANSI_ARGS_((ClientData clientData)); static voidFileNameInit _ANSI_ARGS_((void)); static intSkipToChar _ANSI_ARGS_((char **stringPtr, --- 51,57 ---- static char *DoTildeSubst _ANSI_ARGS_((Tcl_Interp *interp, CONST char *user, Tcl_DString *resultPtr)); static CONST char *ExtractWinRoot _ANSI_ARGS_((CONST char *path, ! Tcl_DString *resultPtr, int offset, Tcl_PathType *typePtr)); static voidFileNameCleanup _ANSI_ARGS_((ClientData clientData)); static voidFileNameInit _ANSI_ARGS_((void)); static intSkipToChar _ANSI_ARGS_((char **stringPtr, *************** *** 94,100 **** ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); if (!tsdPtr->initialized) { tsdPtr->initialized = 1; - tsdPtr->winRootPatternPtr = Tcl_NewStringObj(WIN_ROOT_PATTERN, -1); tsdPtr->macRootPatternPtr = Tcl_NewStringObj(MAC_ROOT_PATTERN, -1); Tcl_CreateThreadExitHandler(FileNameCleanup, NULL); } --- 85,90 ---- *************** *** 122,128 **** ClientData clientData;/* Not used. */ { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - Tcl_DecrRefCount(tsdPtr->winRootPatternPtr); Tcl_DecrRefCount(tsdPtr->macRootPatternPtr); tsdPtr->initialized = 0; } --- 112,117 ---- *************** *** 148,205 **** */ static CONST char * ! ExtractWinRoot(path, resultPtr, offset) CONST char *path;/* Path to parse. */ Tcl_DString *resultPtr;/* Buffer to hold result. */ int offset;/* Offset in buffer where result should be * stored. */ { - int length; - Tcl_RegExp re; - char *dummy, *tail, *drive, *hostStart, *hostEnd, *shareStart, - *shareEnd, *lastSlash; - ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); - - /* - * Initialize the path name parser for Windows path names. - */ - FileNameInit(); - re = Tcl_GetRegExpFromObj(NULL, tsdPtr->winRootPatternPtr, REG_ADVANCED); - - /* - * Match the root portion of a Windows path name. - */ ! if (!Tcl_RegExpExec(NULL, re, path, path)) { ! return path; } ! Tcl_DStringSetLength(resultPtr, offset); ! Tcl_RegExpRange(re, 0, &dummy, &tail); ! Tcl_RegExpRange(re, 2, &drive, &dummy); ! Tcl_RegExpRange(re, 3, &hostStart, &hostEnd); ! Tcl_RegExpRange(re, 4, &shareStart, &shareEnd); ! Tcl_RegExpRange(re, 6, &lastSlash, &dummy); ! ! if (drive != NULL) { ! Tcl_DStringAppend(resultPtr, drive, 2); ! if (lastSlash != NULL) { Tcl_DStringAppend(resultPtr, "/", 1); } - } else if (shareStart != NULL) { Tcl_DStringAppend(resultPtr, "//", 2); ! length = hostEnd - hostStart; ! Tcl_DStringAppend(resultPtr, hostStart, length); Tcl_DStringAppend(resultPtr, "/", 1); ! length = shareEnd - shareStart; ! Tcl_DStringAppend(resultPtr, shareStart, length); } else { Tcl_DStringAppend(resultPtr, "/", 1); } - return tail; } /* --- 137,215 ---- */ static CONST char * ! ExtractWinRoot(path, resultPtr, offset, typePtr) CONST char *path;/* Path to parse. */ Tcl_DString *resultPtr;/* Buffer to hold result. */ int offset;/* Offset in buffer where result should be * stored. */ + Tcl_PathType *typePtr;/* Where to store pathType result */ { FileNameInit(); ! if (path[0] == '/' || path[0] == '\\') { ! /* Might be a UNC or Vol-Relative path */ ! char *host, *share, *tail; ! int hlen, slen; ! if (path[1] != '/' && path[1] != '\\') { ! *typePtr = TCL_PATH_VOLUME_RELATIVE; ! Tcl_DStringAppend(resultPtr, "/", 1); ! return &path[1]; } + host = (char *)&path[2]; ! /* Skip seperators */ ! while (host[0] == '/' || host[0] == '\\') host++; ! for (hlen = 0; host[hlen];hlen++) { ! if (host[hlen] == '/' || host[hlen] == '\\') ! break; ! } ! if (host[hlen] == 0 || host[hlen+1] == 0) { ! *typePtr = TCL_PATH_VOLUME_RELATIVE; Tcl_DStringAppend(resultPtr, "/", 1); + return &path[2]; + } + Tcl_DStringSetLength(resultPtr, offset); + share = &host[hlen]; + + /* Skip seperators */ + while (share[0] == '/' || share[0] == '\\') share++; + + for (slen = 0; share[slen];slen++) { + if (share[slen] == '/' || share[slen] == '\\') + break; } Tcl_DStringAppend(resultPtr, "//", 2); ! Tcl_DStringAppend(resultPtr, host, hlen); Tcl_DStringAppend(resultPtr, "/", 1); ! Tcl_DStringAppend(resultPtr, share, slen); ! ! tail = &share[slen]; ! ! /* Skip seperators */ ! while (tail[0] == '/' || tail[0] == '\\') tail++; ! ! *typePtr = TCL_PATH_ABSOLUTE; ! return tail; ! } else if (path[1] == ':') { ! /* Might be a drive sep */ ! Tcl_DStringSetLength(resultPtr, offset); ! ! if (path[2] != '/' && path[2] != '\\') { ! *typePtr = TCL_PATH_VOLUME_RELATIVE; ! Tcl_DStringAppend(resultPtr, path, 2); ! return &path[2]; } else { + *typePtr = TCL_PATH_ABSOLUTE; + Tcl_DStringAppend(resultPtr, path, 2); Tcl_DStringAppend(resultPtr, "/", 1); + return &path[3]; + } + } else { + *typePtr = TCL_PATH_RELATIVE; + return path; } } /* *************** *** 269,298 **** case TCL_PLATFORM_WINDOWS: if (path[0] != '~') { ! tsdPtr = TCL_TSD_INIT(&dataKey); ! /* ! * Since we have eliminated the easy cases, check for ! * drive relative paths using the regular expression. ! */ ! ! FileNameInit(); ! re = Tcl_GetRegExpFromObj(NULL, tsdPtr->winRootPatternPtr, ! REG_ADVANCED); ! ! if (Tcl_RegExpExec(NULL, re, path, path)) { ! char *drive, *dummy, *unixRoot, *lastSlash; ! Tcl_RegExpRange(re, 2, &drive, &dummy); ! Tcl_RegExpRange(re, 5, &unixRoot, &dummy); ! Tcl_RegExpRange(re, 6, &lastSlash, &dummy); ! if (unixRoot || (drive && !lastSlash)) { ! type = TCL_PATH_VOLUME_RELATIVE; ! } ! } else { ! type = TCL_PATH_RELATIVE; ! } } break; } --- 279,291 ---- case TCL_PLATFORM_WINDOWS: if (path[0] != '~') { ! Tcl_DString ds; ! Tcl_DStringInit(&ds); ! (VOID)ExtractWinRoot(path, &ds, 0, &type); ! Tcl_DStringFree(&ds); } break; } *************** *** 488,495 **** { int length; CONST char *p, *elementStart; ! p = ExtractWinRoot(path, bufPtr, 0); /* * Terminate the root portion, if we matched something. --- 481,489 ---- { int length; CONST char *p, *elementStart; + Tcl_PathType type = TCL_PATH_ABSOLUTE; ! p = ExtractWinRoot(path, bufPtr, 0, &type); /* * Terminate the root portion, if we matched something. *************** *** 738,743 **** --- 732,738 ---- Tcl_DString buffer; char c, *dest; CONST char *p; + Tcl_PathType type = TCL_PATH_ABSOLUTE; Tcl_DStringInit(&buffer); oldLength = Tcl_DStringLength(resultPtr); *************** *** 814,820 **** */ for (i = 0; i < argc; i++) { ! p = ExtractWinRoot(argv[i], resultPtr, oldLength); length = Tcl_DStringLength(resultPtr); /* --- 809,815 ---- */ for (i = 0; i < argc; i++) { ! p = ExtractWinRoot(argv[i], resultPtr, oldLength, &type); length = Tcl_DStringLength(resultPtr); /* PatchFiles: generic/tclFilename.c - foundin initialized to: "obsolete: 8.2"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "69. Other"
- title initialized to:
Tcl_SplitPath, JoinPath and PathType are extremely slow
- type initialized to: "Bug"
Ticket change [052b7c0699] (rid 89009) by welch on 2000-10-26 08:09:12:
- closedate changed to: "2000-10-26T01:09:12"
- closer changed to: "welch"
- priority changed to: "3 Low"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [ea16f7602f] (rid 103312) by dgp on 2001-04-14 02:14:37:
- closedate changed to: "2001-04-13T19:14:37"
- closer changed to: "dgp"
- subsystem changed to: "36. Pathname Management"