Tcl Source Code

Check-in [e35f61d57e]
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:Optimize case of all single-byte chars.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dgp-string-find
Files: files | file ages | folders
SHA1: e35f61d57e6f322f8c16868d1c38e2dcfb47dc18
User & Date: dgp 2016-11-07 20:04:22
Context
2016-11-07
20:11
Refactor to channel all [string first] functions through a single implementation. check-in: 5fd1a339d3 user: dgp tags: trunk
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
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to generic/tclStringObj.c.

  2892   2892   		return (try - bh);
  2893   2893   	    }
  2894   2894   	    try++;
  2895   2895   	}
  2896   2896   	return -1;
  2897   2897       }
  2898   2898   
  2899         -    /* TODO: Detect and optimize case with single byte chars only */
         2899  +    lh = Tcl_GetCharLength(haystack);
         2900  +    if (haystack->bytes && (lh == haystack->length)) {
         2901  +	/* haystack is all single-byte chars */
  2900   2902   
  2901         -    {
         2903  +	if (needle->bytes && (ln == needle->length)) {
         2904  +	    /* needle is also all single-byte chars */
         2905  +	    char *found = strstr(haystack->bytes + start, needle->bytes);
         2906  +
         2907  +	    if (found) {
         2908  +		return (found - haystack->bytes);
         2909  +	    } else {
         2910  +		return -1;
         2911  +	    }
         2912  +	} else {
         2913  +	    /*
         2914  +	     * Cannot find substring with a multi-byte char inside
         2915  +	     * a string with no multi-byte chars.
         2916  +	     */
         2917  +	    return -1;
         2918  +	}
         2919  +    } else {
  2902   2920   	Tcl_UniChar *try, *end, *uh;
  2903   2921   	Tcl_UniChar *un = Tcl_GetUnicodeFromObj(needle, &ln);
  2904   2922   
  2905   2923   	uh = Tcl_GetUnicodeFromObj(haystack, &lh);
  2906   2924   	end = uh + lh;
  2907   2925   
  2908   2926   	try = uh + start;