diff options
author | dgp <dgp@users.sourceforge.net> | 2016-10-28 14:06:15 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-10-28 14:06:15 (GMT) |
commit | 4968966c028c3577f5ef3e604cf1e98b7c37d824 (patch) | |
tree | 6c4cb117e520328dd5159d4a1eb8d8309e5f8160 /generic/tclStringObj.c | |
parent | e4a82e14e114848e09bb17073c531eba791aacee (diff) | |
download | tcl-4968966c028c3577f5ef3e604cf1e98b7c37d824.zip tcl-4968966c028c3577f5ef3e604cf1e98b7c37d824.tar.gz tcl-4968966c028c3577f5ef3e604cf1e98b7c37d824.tar.bz2 |
Add obvious optimization to Tcl_GetCharLength().
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r-- | generic/tclStringObj.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 2930fa1..e878167 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -409,6 +409,15 @@ Tcl_GetCharLength( int numChars; /* + * Quick, no-shimmer return for short string reps. + */ + + if ((objPtr->bytes) && (objPtr->length < 2)) { + /* 0 bytes -> 0 chars; 1 byte -> 1 char */ + return objPtr->length; + } + + /* * Optimize the case where we're really dealing with a bytearray object * without string representation; we don't need to convert to a string to * perform the get-length operation. |