Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 0970544aff38d6fc6dc40d394d11d97b63a17535
Ticket: 219109ffffffffffffffffffffffffffffffffff
string repeat speedup by pre-allocating TclObj
User & Date: nobody on 2000-10-26 01:10:55
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    OriginalBugID: 6018 RFE
    Version: 8.3.1
    SubmitDate: '2000-07-18'
    LastModified: '2000-09-26'
    Severity: LOW
    Status: Released
    Submitter: techsupp
    ChangedBy: hobbs
    OS: All
    FixedDate: '2000-09-26'
    FixedInVersion: 8.4a2
    ClosedDate: '2000-10-25'
    
    
    Name:
    
    Bob Techentin
    
    
    
    Comments:
    
    It would probably be even more efficient to copy the guts of 
    
        AppendUtfToUtfRep (in tclStringObj.c) but that might be
    
        reaching down to too low a level for this command.  I tried it
    
        and got 75% speedup, but it core dumps in the corner cases in
    
        the test suite.
    
    
    
    DesiredBehavior:
    
    The new [string repeat] command will iteratively call Tcl_AppendToObj() 
    
    to build up a repeating string.  This causes several calls to reallocate more
    
    memory for the result object.  It is more efficient to call Tcl_SetObjLength()
    
    once before the appends, so that it is not necessary to reallocate memory
    
    while building up the string.  This results in about a 20% speedup on my
    
    system, and reduces the chances of the automatic allocator using too much
    
    memory (it doubles the object length each time).
    
    
    
    Patch:
    
    *** tclCmdMZ.c.orig     Mon Jul 17 14:51:48 2000
    
    --- tclCmdMZ.c  Mon Jul 17 15:26:56 2000
    
    ***************
    
    *** 1823,1828 ****
    
    --- 1823,1829 ----
    
      
    
                string1 = Tcl_GetStringFromObj(objv[2], &length1);
    
                if (length1 > 0) {
    
    +               Tcl_SetObjLength(resultPtr, count*length1);
    
                    for (index = 0; index < count; index++) {
    
                        Tcl_AppendToObj(resultPtr, string1, length1);
    
                    }
    
    
    
    PatchFiles:
    
    tclCmdMZ.c
    
    
    
    
    
    That simple fix unfortunately doesn't have the desired effect,
    but I've changed around 8.4a2 to use ckalloc directly for the
    same effect. 
    -- 09/26/2000 hobbs
    
  4. foundin changed to: "obsolete: 8.3.1"
  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: "81. Bundled Packages"
  10. title changed to: "string repeat speedup by pre-allocating TclObj"
  11. type changed to: "RFE"