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 | 790b302275b213db52a57206eed6821f165f8d64 (patch) | |
tree | 987324200646eaa485ded0e53970555ff3033b7c /generic/tclStringObj.c | |
parent | dc11ffbbdb8b86b68b1c857612ef4d6ea57115dc (diff) | |
download | tcl-790b302275b213db52a57206eed6821f165f8d64.zip tcl-790b302275b213db52a57206eed6821f165f8d64.tar.gz tcl-790b302275b213db52a57206eed6821f165f8d64.tar.bz2 |
Optimize case of all single-byte chars.
Diffstat (limited to 'generic/tclStringObj.c')
-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); |