Tcl Source Code

Check-in [9bc07dee24]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Consolidate the "find empty string" cases.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dgp-string-find
Files: files | file ages | folders
SHA1: 9bc07dee2411083b544e4bd3095f81259c1aa631
User & Date: dgp 2016-11-07 19:41:15
Context
2016-11-07
20:04
Optimize case of all single-byte chars. Closed-Leaf check-in: e35f61d57e user: dgp tags: dgp-string-find
19:41
Consolidate the "find empty string" cases. check-in: 9bc07dee24 user: dgp tags: dgp-string-find
19:28
Implement direct eval [string first] with the refactored engine. check-in: 7fb4fda651 user: dgp tags: dgp-string-find
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclStringObj.c.

2858
2859
2860
2861
2862
2863
2864
2865










2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
....
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
int
TclStringFind(
    Tcl_Obj *needle,
    Tcl_Obj *haystack,
    unsigned int start)
{
    int ln, lh;











    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;

	try = bh + start;
	while (try + ln <= end) {
	    try = memchr(try, bn[0], end - try);

................................................................................

    /* TODO: Detect and optimize case with single byte chars only */

    {
	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;

	try = uh + start;
	while (try + ln <= end) {
	    if ((*try == *un)
		    && (0 == memcmp(try+1, un+1, (ln-1)*sizeof(Tcl_UniChar)))) {






|
>
>
>
>
>
>
>
>
>
>





<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<







2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880










2881
2882
2883
2884
2885
2886
2887
....
2898
2899
2900
2901
2902
2903
2904





2905
2906
2907
2908
2909
2910
2911
int
TclStringFind(
    Tcl_Obj *needle,
    Tcl_Obj *haystack,
    unsigned int start)
{
    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);











	bh = Tcl_GetByteArrayFromObj(haystack, &lh);
	end = bh + lh;

	try = bh + start;
	while (try + ln <= end) {
	    try = memchr(try, bn[0], end - try);

................................................................................

    /* TODO: Detect and optimize case with single byte chars only */

    {
	Tcl_UniChar *try, *end, *uh;
	Tcl_UniChar *un = Tcl_GetUnicodeFromObj(needle, &ln);






	uh = Tcl_GetUnicodeFromObj(haystack, &lh);
	end = uh + lh;

	try = uh + start;
	while (try + ln <= end) {
	    if ((*try == *un)
		    && (0 == memcmp(try+1, un+1, (ln-1)*sizeof(Tcl_UniChar)))) {