Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 271c6d31b8131a0751ed6e3872c079f505d5c9a7
Ticket: 1529526fffffffffffffffffffffffffffffffff
Avoid some unnecesary strlen()s
User & Date: afredd on 2006-07-27 08:15:07
Changes

  1. assignee changed to: "dkf"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    
    In the call to Tcl_SetStringObj in the STORE_ARY macro
    in StoreStatData(), the string length can be
    determined since they are all string literals.
    So the attached patch saves unnecesary 12 strlen()s
    per call to "file stat ...".
    NB. The use of ("" fieldName) is simply to ensure that
    if STORE_ARY is called with something other than
    a string literal as the fieldName, then the compiler
    will helpfully given an error. 
    
    --
    This same technique of determining the length of a
    string literal using (sizeof(strLit) - 1) could be
    useful for Tcl_NewStringObj & Tcl_DStringAppend which
    are often called with a string literal and a length
    of -1 in the core. So something like these macros
    added to tclInt.h and then used in the core would
    save some additional unnecesary strlen()s:
    
    
    /* Macro to determine the length of a "string literal"
     * at compile time.
     * NB. The use of (strLit "") below ensures that the
     * compiler will report an error if anything other
     * than a string literal is given to the macro.
     */
    #define StrLitLen(strLit) \
      ((int) (sizeof(strLit "") - 1))
    
    #define TclNewStrLitObj(strLit) \
      Tcl_NewStringObj(strLit, strLitLen(strLit))
    
    #define TclDStrLitAppend(dsPtr, strLit) \
      Tcl_DStringAppend(dsPtr, strLit, strLitLen(strLit))
    
    
    
    So calls like:
      Tcl_NewStringObj("foo", -1)
    would then be written as
      TclNewStrLitObj("foo")
    and would be expanded as
      Tcl_NewStringObj("foo", 3)
    
    
    (There are about 100 calls to Tcl_NewStringObj &
    Tcl_DStringAppend which could use these macros to
    avoid an unnecesary strlen) 
    
    
    
  4. foundin changed to: "None"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "afredd"
  10. subsystem changed to: "16. Commands A-H"
  11. title changed to: "Avoid some unnecesary strlen()s"
  12. type changed to: "Patch"