Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] ztrsub() execution time / 2



Sebastian Gniazdowski wrote on Wed, Oct 17, 2018 at 06:29:08 +0200:
> diff --git a/Src/utils.c b/Src/utils.c
> index 914e30c..1eb8c71 100644
> --- a/Src/utils.c
> +++ b/Src/utils.c
> @@ -5058,23 +5058,23 @@ ztrlenend(char const *s, char const *eptr)
>  #endif /* MULTIBYTE_SUPPORT */
>  
>  /* Subtract two pointers in a metafied string. */
>  
>  /**/
>  mod_export int
>  ztrsub(char const *t, char const *s)
>  {
>      int l = t - s;
>  
>      while (s != t) {
> -	if (*s++ == Meta) {
> +	if (*s++ == Meta || (s != t && *s++ == Meta)) {

Thank you for generating the diff with additional context lines.

As far as I can tell, this patch is the sort of transformation that an
optimizing compiler should do by itself.  In fact, I'm having a hard time
seeing how the sequence of "BRANCH IF EQUAL" / "BRANCH IF NOT EQUAL" /
"INCREMENT" assembly instructions would be altered by the patch.

If your profiling was performed on zsh compiled with -O3, I would suggest that
you file a bug against your compiler's optimizer.

>  #ifdef DEBUG
>  	    if (! *s || s == t)
>  		fprintf(stderr, "BUG: substring ends in the middle of a metachar in ztrsub()\n");
>  	    else
>  #endif
>  	    s++;
>  	    l--;

Cheers,

Daniel

>  	}
>      }
>      return l;
>  }



Messages sorted by: Reverse Date, Date, Thread, Author