summaryrefslogtreecommitdiffstats
path: root/generic/tclStringObj.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2016-11-07 19:41:15 (GMT)
committerdgp <dgp@users.sourceforge.net>2016-11-07 19:41:15 (GMT)
commitdc11ffbbdb8b86b68b1c857612ef4d6ea57115dc (patch)
treea14f0f0aef80322aaafa7ea256b729d10e9c88b5 /generic/tclStringObj.c
parent1571dc01bb35c5a3255f68feb7f92f12ddad3654 (diff)
downloadtcl-dc11ffbbdb8b86b68b1c857612ef4d6ea57115dc.zip
tcl-dc11ffbbdb8b86b68b1c857612ef4d6ea57115dc.tar.gz
tcl-dc11ffbbdb8b86b68b1c857612ef4d6ea57115dc.tar.bz2
Consolidate the "find empty string" cases.
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r--generic/tclStringObj.c27
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;