diff options
author | dgp <dgp@users.sourceforge.net> | 2016-11-07 20:04:22 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-11-07 20:04:22 (GMT) |
commit | 96b75029d111bab1f01acea88795c774b96b4f6e (patch) | |
tree | 987324200646eaa485ded0e53970555ff3033b7c | |
parent | b2c104021f192aefe7b82d283176e941b7f0a01e (diff) | |
download | tcl-96b75029d111bab1f01acea88795c774b96b4f6e.zip tcl-96b75029d111bab1f01acea88795c774b96b4f6e.tar.gz tcl-96b75029d111bab1f01acea88795c774b96b4f6e.tar.bz2 |
Optimize case of all single-byte chars.dgp_string_find
-rw-r--r-- | generic/tclStringObj.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 0c0121e..edba881 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2896,9 +2896,27 @@ TclStringFind( return -1; } - /* TODO: Detect and optimize case with single byte chars only */ + lh = Tcl_GetCharLength(haystack); + if (haystack->bytes && (lh == haystack->length)) { + /* haystack is all single-byte chars */ - { + if (needle->bytes && (ln == needle->length)) { + /* needle is also all single-byte chars */ + char *found = strstr(haystack->bytes + start, needle->bytes); + + if (found) { + return (found - haystack->bytes); + } else { + return -1; + } + } else { + /* + * Cannot find substring with a multi-byte char inside + * a string with no multi-byte chars. + */ + return -1; + } + } else { Tcl_UniChar *try, *end, *uh; Tcl_UniChar *un = Tcl_GetUnicodeFromObj(needle, &ln); |