Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e7199037006d014221b841bda0d89844962c781f
Ticket: 218944ffffffffffffffffffffffffffffffffff
Tcl_SplitPath on Windows speed-up patch
User & Date: nobody on 2000-10-26 01:08:26
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 2867 RFE
    Version: 8.2
    SubmitDate: '1999-09-23'
    LastModified: '2000-03-01'
    Severity: MED
    Status: Released
    Submitter: techsupp
    ChangedBy: hobbs
    OS: Windows NT
    Machine: X86
    FixedDate: '2000-03-01'
    FixedInVersion: 8.3.1
    ClosedDate: '2000-10-25'
    
    
    Name:
    
    Matt Newman
    
    
    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...... Which is what this patch
    
        provides. Tha last submission has a wee bug in it, which has bee
    
        resolved. This patch passes all the fileName tests.
    
    
    Patch:
    
    Index: tcl8.2/generic/tclFileName.c
    
    ===================================================================
    
    RCS file: /cvs/tcl/tcl8.2/generic/tclFileName.c,v
    
    retrieving revision 1.1
    
    diff -w -b -r1.1 tclFileName.c
    
    13c13
    
    <  * RCS: @(#) $Id: tclFileName.c,v 1.1 1999/08/19 12:32:00 matt Exp $
    
    ---
    
    >  * RCS: @(#) $Id: tclFileName.c,v 1.2 1999/09/22 14:00:43 matt Exp $
    
    21,28d20
    
    <  * 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]:)|[/\\\\][/\\\\]+([^/\\\\]+)[/\\\\]+([^/\\\\]+)|([/\\\\]))([/\\\\])*"
    
    < 
    
    < /*
    
    43d34
    
    <     Tcl_Obj *winRootPatternPtr;
    
    63c54
    
    <     Tcl_DString *resultPtr, int offset));
    
    ---
    
    >     Tcl_DString *resultPtr, int offset, Tcl_PathType *typePtr));
    
    97d87
    
    < tsdPtr->winRootPatternPtr = Tcl_NewStringObj(WIN_ROOT_PATTERN, -1);
    
    125d114
    
    <     Tcl_DecrRefCount(tsdPtr->winRootPatternPtr);
    
    151c140
    
    < ExtractWinRoot(path, resultPtr, offset)
    
    ---
    
    > ExtractWinRoot(path, resultPtr, offset, typePtr)
    
    155a145
    
    >     Tcl_PathType *typePtr;/* Where to store pathType result */
    
    157,166d146
    
    <     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.
    
    <      */
    
    < 
    
    169,173d148
    
    <     re = Tcl_GetRegExpFromObj(NULL, tsdPtr->winRootPatternPtr, REG_ADVANCED);
    
    < 
    
    <     /*
    
    <      * Match the root portion of a Windows path name.
    
    <      */
    
    175,176c150,158
    
    <     if (!Tcl_RegExpExec(NULL, re, path, path)) {
    
    < return path;
    
    ---
    
    >     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] != '\\') {
    
    >     Tcl_DStringSetLength(resultPtr, offset);
    
    >     *typePtr = TCL_PATH_VOLUME_RELATIVE;
    
    >     Tcl_DStringAppend(resultPtr, "/", 1);
    
    >     return &path[1];
    
    177a160
    
    > host = (char *)&path[2];
    
    179c162,163
    
    <     Tcl_DStringSetLength(resultPtr, offset);
    
    ---
    
    > /* Skip seperators */
    
    > while (host[0] == '/' || host[0] == '\\') host++;
    
    181,189c165,170
    
    <     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) {
    
    ---
    
    > 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;
    
    190a172,182
    
    >     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;
    
    192d183
    
    <     } else if (shareStart != NULL) {
    
    194,195c185
    
    < length = hostEnd - hostStart;
    
    < Tcl_DStringAppend(resultPtr, hostStart, length);
    
    ---
    
    > Tcl_DStringAppend(resultPtr, host, hlen);
    
    197,198c187,203
    
    < length = shareEnd - shareStart;
    
    < Tcl_DStringAppend(resultPtr, shareStart, length);
    
    ---
    
    > 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];
    
    199a205,211
    
    >     char *tail = &path[3];
    
    > 
    
    >     /* Skip seperators */
    
    >     while (tail[0] == '/' || tail[0] == '\\') tail++;
    
    > 
    
    >     *typePtr = TCL_PATH_ABSOLUTE;
    
    >     Tcl_DStringAppend(resultPtr, path, 2);
    
    201c213
    
    <     }
    
    ---
    
    > 
    
    203a216,220
    
    >     } else {
    
    > *typePtr = TCL_PATH_RELATIVE;
    
    > return path;
    
    >     }
    
    > }
    
    272,281c289
    
    < 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);
    
    ---
    
    > Tcl_DString ds;
    
    283,284c291
    
    < if (Tcl_RegExpExec(NULL, re, path, path)) {
    
    <     char *drive, *dummy, *unixRoot, *lastSlash;
    
    ---
    
    > Tcl_DStringInit(&ds);
    
    286,288c293
    
    <     Tcl_RegExpRange(re, 2, &drive, &dummy);
    
    <     Tcl_RegExpRange(re, 5, &unixRoot, &dummy);
    
    <     Tcl_RegExpRange(re, 6, &lastSlash, &dummy);
    
    ---
    
    > (VOID)ExtractWinRoot(path, &ds, 0, &type);
    
    290,295c295
    
    <     if (unixRoot || (drive && !lastSlash)) {
    
    < type = TCL_PATH_VOLUME_RELATIVE;
    
    <     }
    
    < } else {
    
    <     type = TCL_PATH_RELATIVE;
    
    < }
    
    ---
    
    > Tcl_DStringFree(&ds);
    
    490a491
    
    >     Tcl_PathType type = TCL_PATH_ABSOLUTE;
    
    492c493
    
    <     p = ExtractWinRoot(path, bufPtr, 0);
    
    ---
    
    >     p = ExtractWinRoot(path, bufPtr, 0, &type);
    
    740a742
    
    >     Tcl_PathType type = TCL_PATH_ABSOLUTE;
    
    817c819
    
    < p = ExtractWinRoot(argv[i], resultPtr, oldLength);
    
    ---
    
    > p = ExtractWinRoot(argv[i], resultPtr, oldLength, &type);
    
    
    PatchFiles:
    
    generic/tclFilename.c
    
    
    
    
    Would like to include this, but this patch doesn't apply
    (patch programs keeps rejecting each item). 
    -- 02/05/2000 hobbs
    Oh so valiantly and painfully applied based on different versions
    of tclFileName.c.  :^)  Order of magnitude speed increase confirmed,
    with no problems in the test suite.  Will be in 8.3.1. 
    -- 03/01/2000 hobbs
    
  4. foundin changed to: "obsolete: 8.2"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "37. File System"
  10. title changed to: "Tcl_SplitPath on Windows speed-up patch"
  11. type changed to: "Bug"