From 4968966c028c3577f5ef3e604cf1e98b7c37d824 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 28 Oct 2016 14:06:15 +0000 Subject: Add obvious optimization to Tcl_GetCharLength(). --- generic/tclStringObj.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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. -- cgit v0.12