diff options
author | dgp <dgp@users.sourceforge.net> | 2016-11-07 19:41:15 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2016-11-07 19:41:15 (GMT) |
commit | b2c104021f192aefe7b82d283176e941b7f0a01e (patch) | |
tree | a14f0f0aef80322aaafa7ea256b729d10e9c88b5 /generic | |
parent | a4cbbc51f40fedd5a20c14571c23b10d5e311c8a (diff) | |
download | tcl-b2c104021f192aefe7b82d283176e941b7f0a01e.zip tcl-b2c104021f192aefe7b82d283176e941b7f0a01e.tar.gz tcl-b2c104021f192aefe7b82d283176e941b7f0a01e.tar.bz2 |
Consolidate the "find empty string" cases.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclStringObj.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 6e1529c..0c0121e 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2862,22 +2862,22 @@ TclStringFind( Tcl_Obj *haystack, unsigned int start) { - int ln, lh; + int lh, ln = Tcl_GetCharLength(needle); + + if (ln == 0) { + /* + * We don't find empty substrings. Bizarre! + * + * TODO: When we one day make this a true substring + * finder, change this to "return 0" + */ + return -1; + } if (TclIsPureByteArray(needle) && TclIsPureByteArray(haystack)) { unsigned char *end, *try, *bh; unsigned char *bn = Tcl_GetByteArrayFromObj(needle, &ln); - if (ln == 0) { - /* - * We don't find empty substrings. Bizarre! - * - * TODO: When we one day make this a true substring - * finder, change this to "return 0" - */ - return -1; - } - bh = Tcl_GetByteArrayFromObj(haystack, &lh); end = bh + lh; @@ -2902,11 +2902,6 @@ TclStringFind( Tcl_UniChar *try, *end, *uh; Tcl_UniChar *un = Tcl_GetUnicodeFromObj(needle, &ln); - if (ln == 0) { - /* See above */ - return -1; - } - uh = Tcl_GetUnicodeFromObj(haystack, &lh); end = uh + lh; |