Overview
| Artifact ID: | 271c6d31b8131a0751ed6e3872c079f505d5c9a7 |
|---|---|
| Ticket: | 1529526fffffffffffffffffffffffffffffffff
Avoid some unnecesary strlen()s |
| User & Date: | afredd on 2006-07-27 08:15:07 |
Changes
- assignee changed to: "dkf"
- cmimetype changed to: "text/plain"
- 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) - foundin changed to: "None"
- is_private changed to: "0"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "afredd"
- subsystem changed to: "16. Commands A-H"
- title changed to: "Avoid some unnecesary strlen()s"
- type changed to: "Patch"