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

Re: Match to the end of string when using (S) flag



A miracle optimization – via mathematical function!

    __hsmw_region_highlight_data=( )
    : "${text//(#mi)(${~colsearch_pattern})/$(( append(MBEGIN,MEND) ))}"
    region_highlight+=( $__hsmw_region_highlight_data )

    shappend() {
        __hsmw_region_highlight_data+=( "$(( offset + $1 - 1 )) $((
        offset + $2 )) ${__hsmw_hl_color}" )
    }
    functions -M append 2 2 shappend

This gives total time (time of anonymous function wrapping first three
lines) for a complex – three-word A|B|C – input pattern: 44 ms (17 ms in
shappend).

When I do:
    : "${(S)text//*(#bi)(${~colsearch_pattern})/$((
    append(mbegin[1],mend[1]) ))}"

then the time is: 528 ms ! After removing leading star *: 52 ms (18 ms
in shappend).

Time of original one-liner without math-function call: 502 ms.

-- 
  Sebastian Gniazdowski
  psprint@xxxxxxxxxxxx



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