Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: f5add77efeaaa7f9eac73e63ff1d8eee798c6fac
Ticket: 1246897fffffffffffffffffffffffffffffffff
Minor optimsations for Tcl_DStringAppend usage.
User & Date: nobody on 2005-07-28 16:11:31
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    Minor optimisation: there are a few calls to 
    Tcl_DStringAppend with fixed strings, but give a length 
    of -1. Replacing the -1 with the actual length (as is done 
    in other places) would save a strlen.
    eg.
    
    
    tclConfig.c:141:    Tcl_DStringAppend 
    (&cmdName, "::",          -1);
    tclConfig.c:161:    Tcl_DStringAppend 
    (&cmdName, "::pkgconfig", -1);
    tclInterp.c:433:    Tcl_DStringAppend(&script, "lsearch -
    exact", -1);
    tclInterp.c:437:    Tcl_DStringAppend(&script, " [file join 
    [info library] encoding]", -1);
    tclInterp.c:450:    Tcl_DStringAppend(&script, "file join 
    [info library] encoding", -1);
    tclUtil.c:1856:Tcl_DStringAppend(dsPtr, " {", -1);
    tclUtil.c:1858:Tcl_DStringAppend(dsPtr, "{", -1);
    tclUtil.c:1885:    Tcl_DStringAppend(dsPtr, "}", -1);
    
    There are also some where the string being copied is a 
    Tcl_DString, so we could use the corresponding 
    Tcl_DStringLength instead of -1; again saving a strlen.
    
    eg.
    
    tclLoad.c:349:Tcl_DStringAppend(&initName, 
    Tcl_DStringValue(&pkgName), -1);
    tclLoad.c:351:Tcl_DStringAppend
    (&safeInitName, Tcl_DStringValue(&pkgName), -1);
    tclLoad.c:353:        Tcl_DStringAppend(&unloadName, 
    Tcl_DStringValue(&pkgName), -1);
    tclLoad.c:355:        Tcl_DStringAppend
    (&safeUnloadName, Tcl_DStringValue(&pkgName), -1);
    tclNamesp.c:823:Tcl_DStringAppend(&buffer1, 
    Tcl_DStringValue(&buffer2), -1);
    tclNamesp.c:826:Tcl_DStringAppend(&buffer2, 
    Tcl_DStringValue(&buffer1), -1);
    
    (which makes me wonder if the Right Thing is done if 
    any of the above contain embedded NULs in them, as 
    the strlen will give the 'incorrect' length.).
    
    
    Final point, wouldn't the copy loop in Tcl_DStringAppend 
    be quicker as a memcpy and not as a character by 
    character copy in the for loop. I've no empirical evidence, 
    just the (perhaps incorrect!) assumption that the C 
    library's memcpy is quicker than the corresponding for 
    loop. 
    
    Cheers!
    
  4. foundin changed to: "None"
  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: "None"
  10. title changed to: "Minor optimsations for Tcl_DStringAppend usage."
  11. type changed to: "Patch"